Skip to content

Commit

Permalink
fix(#3963): fix test_sync_max_eps_scheduled
Browse files Browse the repository at this point in the history
  • Loading branch information
Deblintrake09 committed Mar 7, 2023
1 parent b4db1fa commit ba25334
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
31 changes: 31 additions & 0 deletions deps/wazuh_testing/wazuh_testing/modules/fim/event_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,37 @@ def callback_integrity_message(line):
return datetime.strptime(match.group(1), '%Y/%m/%d %H:%M:%S'), json.dumps(match.group(2))


def callback_integrity_sync_message(line):
""" Callback that detects if a line contains a integrity sync event
Args:
line (String): string line to be checked by callback in File_Monitor.
Returns:
List: returns a list with formated datetime, And the event's JSON data.
"""
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'), json.dumps(match.group(2))


def callback_detect_integrity_check_global(line):
""" Callback that detects if a line contains an 'integrity_check_global' event
Args:
line (String): string line to be checked by callback in File_Monitor.
Returns:
JSON: returns event's JSON data.
"""
match = callback_detect_integrity_control_event(line)
if match:
if match['type'] == 'integrity_check_global':
return match
return None


def callback_detect_file_integrity_event(line):
""" Callback that detects if a line contains a file integrity event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
from wazuh_testing.modules import DATA, TIER1, AGENT, WINDOWS, LINUX
from wazuh_testing.modules.fim import TEST_DIR_1, TEST_DIRECTORIES, YAML_CONF_MAX_EPS_SYNC, SCHEDULED_MODE
from wazuh_testing.modules.fim import FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS as local_internal_options
from wazuh_testing.modules.fim.event_monitor import (callback_integrity_message, ERR_MSG_INTEGRITY_CONTROL_MSG,
from wazuh_testing.modules.fim.event_monitor import (callback_detect_integrity_check_global,
callback_integrity_sync_message, ERR_MSG_INTEGRITY_CONTROL_MSG,
ERR_MSG_MULTIPLE_FILES_CREATION)
from wazuh_testing.tools.file import delete_path_recursively, write_file
from wazuh_testing.modules.fim.utils import generate_params
Expand Down Expand Up @@ -127,7 +128,6 @@ def create_multiple_files(get_configuration):


# Tests
@pytest.mark.skip("This test is affected by QA Issue #3997, when it is fixed it should be enabled again.")
def test_max_eps_sync_valid_within_range(configure_local_internal_options_module, get_configuration,
create_multiple_files, configure_environment, restart_wazuh):
'''
Expand Down Expand Up @@ -182,13 +182,13 @@ def test_max_eps_sync_valid_within_range(configure_local_internal_options_module

# Find integrity start before attempting to read max_eps.
wazuh_log_monitor.start(timeout=TIMEOUT_CHECK_INTEGRATY_START,
callback=callback_integrity_message,
callback=callback_detect_integrity_check_global,
error_message=ERR_MSG_INTEGRITY_CONTROL_MSG).result()

# Find integrity message for each file created after read max_eps.
total_file_created = max_eps + 5
result = wazuh_log_monitor.start(timeout=TIMEOUT_CHECK_EACH_INTEGRITY_MSG, accum_results=total_file_created,
callback=callback_integrity_message,
callback=callback_integrity_sync_message,
error_message=f'Received less results than expected\
({total_file_created})').result()
# Collect by time received the messages.
Expand Down

0 comments on commit ba25334

Please sign in to comment.