Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IT FIM - Fix Solaris and Macos fails for 4.3 #2977

Merged
merged 3 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/wazuh_testing/wazuh_testing/fim.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ def modify_file_inode(path, name):
path_to_file = os.path.join(path, name)

shutil.copy2(path_to_file, os.path.join(tempfile.gettempdir(), inode_file))
os.replace(os.path.join(tempfile.gettempdir(), inode_file), path_to_file)
shutil.move(os.path.join(tempfile.gettempdir(), inode_file), path_to_file)


def modify_file_win_attributes(path, name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- tags:
- ossec_conf
apply_to_modules:
- MODULE_NAME
- test_basic_usage_realtime_unsupported
sections:
- section: syscheck
elements:
Expand All @@ -13,3 +13,17 @@
attributes:
- check_all: 'yes'
- realtime: 'yes'
- section: sca
elements:
- enabled:
value: 'no'
- section: rootcheck
elements:
- disabled:
value: 'yes'
- section: wodle
attributes:
- name: 'syscollector'
elements:
- disabled:
value: 'yes'
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,40 @@
import os

import pytest
import re
from wazuh_testing import global_parameters
from wazuh_testing.fim import generate_params, regular_file_cud, LOG_FILE_PATH, callback_num_inotify_watches, \
detect_initial_scan, callback_ignore_realtime_flag, CHECK_ALL, REQUIRED_ATTRIBUTES
from wazuh_testing.tools import PREFIX
from wazuh_testing.tools.configuration import load_wazuh_configurations, check_apply_test

# Marks
from wazuh_testing.fim import generate_params, regular_file_cud, detect_initial_scan, callback_ignore_realtime_flag
from wazuh_testing.tools import PREFIX
from wazuh_testing.tools.configuration import load_wazuh_configurations


# Marks
pytestmark = [pytest.mark.darwin, pytest.mark.sunos5, pytest.mark.tier(level=0)]

# variables

# Variables
realtime_flag_timeout = 60
directory_str = os.path.join(PREFIX, 'dir')
test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data')
configurations_path = os.path.join(test_data_path, 'wazuh_conf_check_realtime.yaml')
test_file = 'testfile.txt'
test_directories = [directory_str]

# configurations


conf_params = {'TEST_DIRECTORIES': directory_str, 'MODULE_NAME': __name__}
# Configurations
conf_params = {'TEST_DIRECTORIES': directory_str}
parameters, metadata = generate_params(extra_params=conf_params, modes=['scheduled'])
configurations = load_wazuh_configurations(configurations_path, __name__, params=parameters, metadata=metadata)
local_internal_options = {'syscheck.debug': '2', 'monitord.rotate_log': '0'}
daemons_handler_configuration = {'daemons': ['wazuh-syscheckd']}

# fixtures


# Fixtures
@pytest.fixture(scope='module', params=configurations)
def get_configuration(request):
"""Get configurations from the module."""
return request.param


# tests


# Tests
def test_realtime_unsupported(get_configuration, configure_environment, file_monitoring,
configure_local_internal_options_module, daemons_handler):
'''
Expand Down Expand Up @@ -144,5 +136,5 @@ def test_realtime_unsupported(get_configuration, configure_environment, file_mon
detect_initial_scan(log_monitor)

regular_file_cud(directory_str, log_monitor, file_list=[test_file], time_travel=True, triggers_event=True,
event_mode="scheduled")
event_mode="scheduled", min_timeout=15)

Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,19 @@ def modify_and_check_events(f1, f2, text):
fim.create_file(fim.REGULAR, main_folder, file1, content='')
fim.create_file(fim.REGULAR, aux_folder, file1, content='')
fim.check_time_travel(scheduled, monitor=wazuh_log_monitor)
add = wazuh_log_monitor.start(timeout=3, callback=fim.callback_detect_event,
add = wazuh_log_monitor.start(timeout=10, callback=fim.callback_detect_event,
error_message='Did not receive expected "Sending FIM event: ..." event'
).result()
assert 'added' in add['data']['type'] and file1 in add['data']['path'], \
f"'added' event not matching for {file1}"
with pytest.raises(TimeoutError):
event = wazuh_log_monitor.start(timeout=3, callback=fim.callback_detect_event)
event = wazuh_log_monitor.start(timeout=10, callback=fim.callback_detect_event)
logger.error(f'Unexpected event {event.result()}')
raise AttributeError(f'Unexpected event {event.result()}')
else:
fim.create_file(fim.REGULAR, aux_folder, file1, content='')
with pytest.raises(TimeoutError):
event = wazuh_log_monitor.start(timeout=3, callback=fim.callback_detect_event)
event = wazuh_log_monitor.start(timeout=10, callback=fim.callback_detect_event)
logger.error(f'Unexpected event {event.result()}')
raise AttributeError(f'Unexpected event {event.result()}')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_symbolic_delete_symlink(tags_to_apply, main_folder, aux_folder, get_con
if tags_to_apply == {'monitored_dir'}:
fim.create_file(fim.REGULAR, main_folder, file1, content='')
fim.check_time_travel(scheduled, monitor=wazuh_log_monitor)
wazuh_log_monitor.start(timeout=3, callback=fim.callback_detect_event,
wazuh_log_monitor.start(timeout=10, callback=fim.callback_detect_event,
error_message='Did not receive expected "Sending FIM event: ..." event')

# Remove symlink and don't expect events
Expand All @@ -181,7 +181,7 @@ def test_symbolic_delete_symlink(tags_to_apply, main_folder, aux_folder, get_con
fim.modify_file_content(main_folder, file1, new_content='Sample modification')
fim.check_time_travel(scheduled, monitor=wazuh_log_monitor)
with pytest.raises(TimeoutError):
event = wazuh_log_monitor.start(timeout=3, callback=fim.callback_detect_event)
event = wazuh_log_monitor.start(timeout=10, callback=fim.callback_detect_event)
logger.error(f'Unexpected event {event.result()}')
raise AttributeError(f'Unexpected event {event.result()}')

Expand All @@ -193,6 +193,6 @@ def test_symbolic_delete_symlink(tags_to_apply, main_folder, aux_folder, get_con

fim.modify_file_content(main_folder, file1, new_content='Sample modification 2')
fim.check_time_travel(scheduled, monitor=wazuh_log_monitor)
modify = wazuh_log_monitor.start(timeout=3, callback=fim.callback_detect_event).result()
modify = wazuh_log_monitor.start(timeout=10, callback=fim.callback_detect_event).result()
assert 'modified' in modify['data']['type'] and file1 in modify['data']['path'], \
f"'modified' event not matching for {file1}"
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ def test_symbolic_monitor_symlink(tags_to_apply, main_folder, get_configuration,
if tags_to_apply == {'monitored_dir'}:
fim.create_file(fim.REGULAR, main_folder, file1, content='')
fim.check_time_travel(scheduled, monitor=wazuh_log_monitor)
add = wazuh_log_monitor.start(timeout=3, callback=fim.callback_detect_event).result()
add = wazuh_log_monitor.start(timeout=10, callback=fim.callback_detect_event).result()
assert 'added' in add['data']['type'] and file1 in add['data']['path'], \
"'added' event not matching"

# Modify the linked file and expect an event
fim.modify_file_content(main_folder, file1, 'Sample modification')
fim.check_time_travel(scheduled, monitor=wazuh_log_monitor)
modify = wazuh_log_monitor.start(timeout=3, callback=fim.callback_detect_event,
modify = wazuh_log_monitor.start(timeout=10, callback=fim.callback_detect_event,
error_message='Did not receive expected '
'"Sending FIM event: ..." event').result()
assert 'modified' in modify['data']['type'] and file1 in modify['data']['path'], \
Expand All @@ -179,7 +179,7 @@ def test_symbolic_monitor_symlink(tags_to_apply, main_folder, get_configuration,
# Delete the linked file and expect an event
delete_f(main_folder, file1)
fim.check_time_travel(scheduled, monitor=wazuh_log_monitor)
delete = wazuh_log_monitor.start(timeout=3, callback=fim.callback_detect_event,
delete = wazuh_log_monitor.start(timeout=10, callback=fim.callback_detect_event,
error_message='Did not receive expected '
'"Sending FIM event: ..." event').result()
assert 'deleted' in delete['data']['type'] and file1 in delete['data']['path'], \
Expand Down