Skip to content

Commit

Permalink
fix(#1915): fix callbacks and fixture import
Browse files Browse the repository at this point in the history
  • Loading branch information
Deblintrake09 committed Nov 30, 2022
1 parent 5bd0df6 commit 39c99d2
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion deps/wazuh_testing/wazuh_testing/modules/fim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
CB_DATABASE_FULL_COULD_NOT_INSERT_KEY = r".*registry_key.*Couldn't insert ('.*') entry into DB. The DB is full.*"
CB_COUNT_REGISTRY_ENTRIES = r".*Fim registry entries count: '(\d+)'"
CB_COUNT_REGISTRY_VALUE_ENTRIES = r".*Fim registry values entries count: '(\d+)'"
CB_REGISTRY_DBSYNC_NO_DATA = r".*#!-fim_registry_(.*) dbsync no_data (.+)"
CB_REGISTRY_DBSYNC_NO_DATA = r".*fim_registry_(.*) dbsync no_data (.*)'"
CB_REGISTRY_LIMIT_CAPACITY = r".*Registry database is (\d+)% full."
CB_REGISTRY_DB_BACK_TO_NORMAL = r".*(The registry database status returns to normal)."
CB_REGISTRY_LIMIT_VALUE = r".*Maximum number of registry values to be monitored: '(\d+)'"
Expand Down
8 changes: 5 additions & 3 deletions deps/wazuh_testing/wazuh_testing/modules/fim/event_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ def callback_num_inotify_watches(line):


def callback_sync_start_time(line):
if fim.callback_detect_synchronization(line):
if callback_detect_synchronization(line):
match = re.match(r"(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}).*", line)
if match:
return datetime.strptime(match.group(1), '%Y/%m/%d %H:%M:%S')


def callback_state_event_time(line):
if fim.callback_detect_integrity_event(line):
if callback_detect_integrity_control_event(line):
match = re.match(r"(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}).*", line)
if match:
return datetime.strptime(match.group(1), '%Y/%m/%d %H:%M:%S')
Expand All @@ -167,7 +167,9 @@ def callback_real_time_whodata_started(line):

def callback_detect_registry_integrity_clear_event(line):
event = callback_detect_integrity_control_event(line)
if event and event['component'] == 'fim_registry' and event['type'] == 'integrity_clear':
if event and event['component'] == 'fim_registry_key' and event['type'] == 'integrity_clear':
return True
if event and event['component'] == 'fim_registry_value' and event['type'] == 'integrity_clear':
return True
return None

Expand Down
6 changes: 2 additions & 4 deletions tests/integration/test_fim/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
from wazuh_testing.tools.monitoring import FileMonitor
from wazuh_testing.tools.file import truncate_file, delete_path_recursively, create_file
from wazuh_testing.modules.fim import (WINDOWS_HKEY_LOCAL_MACHINE, MONITORED_KEY, SYNC_INTERVAL_VALUE, KEY_WOW64_64KEY,
FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS, MONITORED_DIR_1)
from wazuh_testing.modules.fim import (registry_parser, KEY_WOW64_64KEY, WINDOWS_HKEY_LOCAL_MACHINE, MONITORED_KEY,
SYNC_INTERVAL_VALUE, FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS, registry_parser)
MONITORED_DIR_1, registry_parser)
from wazuh_testing.modules.fim import event_monitor as evm
from wazuh_testing.modules.fim.utils import create_registry, delete_registry

Expand Down Expand Up @@ -80,7 +78,7 @@ def install_audit(get_configuration):


@pytest.fixture()
def wait_fim_start_function(configuration):
def wait_fim_start(configuration):
""" Wait for realtime start, whodata start or end of initial FIM scan.
Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
@pytest.mark.parametrize('configuration, metadata', zip(configurations, configuration_metadata), ids=test_case_ids)
def test_reports_file_and_nodiff(configuration, metadata, set_wazuh_configuration,
configure_local_internal_options_function, restart_syscheck_function,
create_monitored_folders, wait_fim_start_function):
create_monitored_folders, wait_fim_start):
'''
description: Check if the 'wazuh-syscheckd' daemon reports the file changes (or truncates if required)
in the generated events using the 'nodiff' tag and vice versa. For this purpose, the test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@
'''
import os
import pytest
from wazuh_testing import DATA, WAZUH_SERVICES_START
from wazuh_testing import LOG_FILE_PATH, DATA, WAZUH_SERVICES_START
from wazuh_testing.tools.configuration import load_wazuh_configurations
from wazuh_testing.tools.monitoring import FileMonitor
from wazuh_testing.tools.services import control_service
from wazuh_testing.modules.fim.utils import (find_value_in_event_list, get_sync_msgs, generate_params, create_registry,
modify_registry_value)
from wazuh_testing.modules.fim import (FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS, SCHEDULED_MODE, WINDOWS_REGISTRY,
SYNC_INTERVAL, SYNC_INTERVAL_VALUE, YAML_CONF_REGISTRY_RESPONSE, REG_SZ,
WINDOWS_HKEY_LOCAL_MACHINE, MONITORED_KEY, registry_parser, KEY_WOW64_64KEY)
from wazuh_testing.modules.fim.event_monitor import detect_initial_scan

# Marks
pytestmark = [pytest.mark.win32, pytest.mark.tier(level=1)]
Expand Down Expand Up @@ -150,9 +152,9 @@ def test_registry_sync_after_restart(key_name, value_name, configure_local_inter

modify_registry_value(key_handle, value_name, REG_SZ, 'This is a test with syscheckd down.')
control_service(WAZUH_SERVICES_START)
wazuh_log_monitor = FileMonitor(LOG_FILE_PATH)
detect_initial_scan(wazuh_log_monitor)
events = get_sync_msgs(timeout=SYNC_INTERVAL_VALUE)

events = get_sync_msgs(SYNC_INTERVAL_VALUE)

assert find_value_in_event_list(
os.path.join(WINDOWS_HKEY_LOCAL_MACHINE, key_path), value_name,
events) is not None, f"No sync event was found for {value_path}"
assert find_value_in_event_list(os.path.join(WINDOWS_HKEY_LOCAL_MACHINE, key_path), value_name,
events) is not None, f"No sync event was found for {value_path}"
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@
wazuh_log_monitor = FileMonitor(LOG_FILE_PATH)
local_internal_options = fim.FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS


# Tests
@pytest.mark.parametrize('configuration, metadata', zip(configurations, configuration_metadata), ids=test_case_ids)
@pytest.mark.parametrize('files_number', [configuration_metadata[0]['files']])
def test_sync_overlap(configuration, metadata, set_wazuh_configuration, configure_local_internal_options_function,
create_files_in_folder, restart_syscheck_function, wait_for_fim_start_function):
create_files_in_folder, restart_syscheck_function, wait_fim_start):
'''
description: Check if the 'wazuh-syscheckd' daemon is performing a synchronization at the interval specified in the
configuration, using the 'interval' tag, if a new synchronization is fired, and the last sync message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
@pytest.mark.parametrize('configuration, metadata', zip(configurations, configuration_metadata), ids=test_case_ids)
@pytest.mark.parametrize('files_number', [configuration_metadata[0]['files']])
def test_sync_time(configuration, metadata, set_wazuh_configuration, configure_local_internal_options_function,
create_files_in_folder, restart_syscheck_function, wait_for_fim_start_function):
create_files_in_folder, restart_syscheck_function, wait_fim_start):
'''
description: Check when the 'wazuh-syscheckd' daemon is performing a synchronization, a normal synchronization
will end before the configured `interval` and `max_interval`.
Expand Down

0 comments on commit 39c99d2

Please sign in to comment.