From 8109f4cc3a1d15897a21765b5d7c102c67fc7299 Mon Sep 17 00:00:00 2001 From: Mauro Ezequiel Moltrasio Date: Mon, 2 Feb 2026 16:11:14 +0100 Subject: [PATCH 1/3] feat(tests): unify waiting for events message Print the events a server waits in a common place to reduce code duplication. --- tests/server.py | 1 + tests/test_config_hotreload.py | 6 ----- tests/test_editors/test_nvim.py | 12 --------- tests/test_editors/test_sed.py | 6 ----- tests/test_editors/test_vi.py | 12 --------- tests/test_editors/test_vim.py | 12 --------- tests/test_file_open.py | 23 +++-------------- tests/test_misc.py | 1 - tests/test_path_chmod.py | 11 -------- tests/test_path_chown.py | 45 ++++++++++++--------------------- tests/test_path_unlink.py | 9 ------- 11 files changed, 21 insertions(+), 117 deletions(-) diff --git a/tests/server.py b/tests/server.py index cd0a8c71..eb1d2baf 100644 --- a/tests/server.py +++ b/tests/server.py @@ -113,5 +113,6 @@ def wait_events(self, events: list[Event], ignored: list[Event] = [], strict: bo Raises: TimeoutError: If the required events are not found in 5 seconds. """ + print('Waiting for events:', *events, sep='\n') fs = self.executor.submit(self._wait_events, events, ignored, strict) fs.result(timeout=5) diff --git a/tests/test_config_hotreload.py b/tests/test_config_hotreload.py index 4b5d337d..e47f776d 100644 --- a/tests/test_config_hotreload.py +++ b/tests/test_config_hotreload.py @@ -100,7 +100,6 @@ def test_output_grpc_address_change(fact, fact_config, monitored_dir, server, al process = Process.from_proc() e = Event(process=process, event_type=EventType.CREATION, file=fut, host_path='') - print(f'Waiting for event: {e}') server.wait_events([e]) @@ -114,7 +113,6 @@ def test_output_grpc_address_change(fact, fact_config, monitored_dir, server, al e = Event(process=process, event_type=EventType.OPEN, file=fut, host_path='') - print(f'Waiting for event on alternate server: {e}') alternate_server.wait_events([e]) @@ -138,7 +136,6 @@ def test_paths(fact, fact_config, monitored_dir, ignored_dir, server): e = Event(process=p, event_type=EventType.CREATION, file=fut, host_path='') - print(f'Waiting for event: {e}') server.wait_events([e], ignored=[ignored_event]) @@ -153,7 +150,6 @@ def test_paths(fact, fact_config, monitored_dir, ignored_dir, server): e = Event(process=p, event_type=EventType.OPEN, file=ignored_file, host_path='') - print(f'Waiting for event: {e}') # File Under Test with open(fut, 'w') as f: @@ -185,7 +181,6 @@ def test_paths_addition(fact, fact_config, monitored_dir, ignored_dir, server): e = Event(process=p, event_type=EventType.CREATION, file=fut, host_path='') - print(f'Waiting for event: {e}') server.wait_events([e], ignored=[ignored_event]) @@ -205,6 +200,5 @@ def test_paths_addition(fact, fact_config, monitored_dir, ignored_dir, server): file=ignored_file, host_path=''), Event(process=p, event_type=EventType.OPEN, file=fut, host_path='') ] - print(f'Waiting for events: {events}') server.wait_events(events) diff --git a/tests/test_editors/test_nvim.py b/tests/test_editors/test_nvim.py index b61bdf1c..32175d42 100644 --- a/tests/test_editors/test_nvim.py +++ b/tests/test_editors/test_nvim.py @@ -20,9 +20,6 @@ def test_new_file(editor_container, server): file=fut, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) @@ -67,9 +64,6 @@ def test_open_file(editor_container, server): file=f'{fut}~', host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) @@ -92,9 +86,6 @@ def test_new_file_ovfs(editor_container, server): file=fut, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) @@ -145,7 +136,4 @@ def test_open_file_ovfs(editor_container, server): file=f'{fut}~', host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) diff --git a/tests/test_editors/test_sed.py b/tests/test_editors/test_sed.py index ed979f66..99accb88 100644 --- a/tests/test_editors/test_sed.py +++ b/tests/test_editors/test_sed.py @@ -34,9 +34,6 @@ def test_sed(vi_container, server): file=sed_tmp_file, host_path='', owner_uid=0, owner_gid=0), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) @@ -76,7 +73,4 @@ def test_sed_ovfs(vi_container, server): file=sed_tmp_file, host_path='', owner_uid=0, owner_gid=0), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) diff --git a/tests/test_editors/test_vi.py b/tests/test_editors/test_vi.py index 59013636..97dbce38 100644 --- a/tests/test_editors/test_vi.py +++ b/tests/test_editors/test_vi.py @@ -35,9 +35,6 @@ def test_new_file(vi_container, server): file=swap_file, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) @@ -82,9 +79,6 @@ def test_new_file_ovfs(vi_container, server): file=swap_file, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) @@ -145,9 +139,6 @@ def test_open_file(vi_container, server): file=swap_file, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) @@ -220,7 +211,4 @@ def test_open_file_ovfs(vi_container, server): file=swap_file, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) diff --git a/tests/test_editors/test_vim.py b/tests/test_editors/test_vim.py index b3778c91..8919362b 100644 --- a/tests/test_editors/test_vim.py +++ b/tests/test_editors/test_vim.py @@ -33,9 +33,6 @@ def test_new_file(editor_container, server): file=swap_file, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) @@ -78,9 +75,6 @@ def test_new_file_ovfs(editor_container, server): file=swap_file, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) @@ -140,9 +134,6 @@ def test_open_file(editor_container, server): file=swap_file, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) @@ -214,7 +205,4 @@ def test_open_file_ovfs(editor_container, server): file=swap_file, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events, strict=True) diff --git a/tests/test_file_open.py b/tests/test_file_open.py index c47272c7..dac8eedf 100644 --- a/tests/test_file_open.py +++ b/tests/test_file_open.py @@ -1,8 +1,6 @@ import multiprocessing as mp import os -import docker - from event import Event, EventType, Process @@ -23,7 +21,6 @@ def test_open(fact, monitored_dir, server): e = Event(process=Process.from_proc(), event_type=EventType.CREATION, file=fut, host_path='') - print(f'Waiting for event: {e}') server.wait_events([e]) @@ -46,10 +43,8 @@ def test_multiple(fact, monitored_dir, server): with open(fut, 'w') as f: f.write('This is a test') - e = Event(process=process, event_type=EventType.CREATION, - file=fut, host_path='') - print(f'Waiting for event: {e}') - events.append(e) + events.append( + Event(process=process, event_type=EventType.CREATION, file=fut, host_path='')) server.wait_events(events) @@ -69,10 +64,8 @@ def test_multiple_access(fact, test_file, server): with open(test_file, 'a+') as f: f.write('This is a test') - e = Event(process=Process.from_proc(), file=test_file, - host_path=test_file, event_type=EventType.OPEN) - print(f'Waiting for event: {e}') - events.append(e) + events.append(Event(process=Process.from_proc(), file=test_file, + host_path=test_file, event_type=EventType.OPEN)) server.wait_events(events) @@ -105,7 +98,6 @@ def test_ignored(fact, test_file, ignored_dir, server): e = Event(process=p, event_type=EventType.OPEN, file=test_file, host_path=test_file) - print(f'Waiting for event: {e}') server.wait_events([e], ignored=[ignored_event]) @@ -140,10 +132,8 @@ def test_external_process(fact, monitored_dir, server): creation = Event(process=p, event_type=EventType.CREATION, file=fut, host_path='') - print(f'Waiting for event: {creation}') write_access = Event( process=p, event_type=EventType.OPEN, file=fut, host_path='') - print(f'Waiting for event: {write_access}') try: server.wait_events([creation, write_access]) @@ -174,9 +164,6 @@ def test_overlay(fact, test_container, server): file=fut, host_path='') ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events) @@ -197,7 +184,6 @@ def test_mounted_dir(fact, test_container, ignored_dir, server): loginuid=pow(2, 32)-1) event = Event(process=process, event_type=EventType.CREATION, file=fut, host_path='') - print(f'Waiting for event: {event}') server.wait_events([event]) @@ -219,6 +205,5 @@ def test_unmonitored_mounted_dir(fact, test_container, test_file, server): loginuid=pow(2, 32)-1) event = Event(process=process, event_type=EventType.OPEN, file=fut, host_path=test_file) - print(f'Waiting for event: {event}') server.wait_events([event]) diff --git a/tests/test_misc.py b/tests/test_misc.py index 71c662dd..8b89c43b 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -62,6 +62,5 @@ def test_d_path_sanitization(fact, monitored_dir, server, run_self_deleter, dock loginuid=pow(2, 32)-1) event = Event(process=process, event_type=EventType.OPEN, file=fut, host_path=host_path) - print(f'Waiting for event: {event}') server.wait_events([event]) diff --git a/tests/test_path_chmod.py b/tests/test_path_chmod.py index 4b62e2c2..69299838 100644 --- a/tests/test_path_chmod.py +++ b/tests/test_path_chmod.py @@ -22,8 +22,6 @@ def test_chmod(fact, monitored_dir, server): e = Event(process=Process.from_proc(), event_type=EventType.PERMISSION, file=fut, host_path=fut, mode=mode) - print(f'Waiting for event: {e}') - server.wait_events([e]) @@ -84,7 +82,6 @@ def test_ignored(fact, test_file, ignored_dir, server): e = Event(process=process, event_type=EventType.PERMISSION, file=test_file, host_path=test_file, mode=mode) - print(f'Waiting for event: {e}') server.wait_events([e], ignored=[ignored_event]) @@ -118,7 +115,6 @@ def test_external_process(fact, monitored_dir, server): event = Event(process=process, event_type=EventType.PERMISSION, file=fut, host_path='', mode=mode) - print(f'Waiting for event: {event}') try: server.wait_events([event]) @@ -170,9 +166,6 @@ def test_overlay(fact, test_container, server): file=fut, host_path='', mode=int(mode, 8)), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events) @@ -218,9 +211,6 @@ def test_mounted_dir(fact, test_container, ignored_dir, server): host_path='', mode=int(mode, 8)), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events) @@ -254,6 +244,5 @@ def test_unmonitored_mounted_dir(fact, test_container, test_file, server): loginuid=pow(2, 32)-1) event = Event(process=process, event_type=EventType.PERMISSION, file=fut, host_path=test_file, mode=int(mode, 8)) - print(f'Waiting for event: {event}') server.wait_events([event]) diff --git a/tests/test_path_chown.py b/tests/test_path_chown.py index d318f4eb..3ae09974 100644 --- a/tests/test_path_chown.py +++ b/tests/test_path_chown.py @@ -39,13 +39,13 @@ def test_chown(fact, test_container, server): container_id=test_container.id[:12], loginuid=loginuid) chown = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chown', - args=chown_cmd, - name='chown', - container_id=test_container.id[:12], - loginuid=loginuid) + uid=0, + gid=0, + exe_path='/usr/bin/chown', + args=chown_cmd, + name='chown', + container_id=test_container.id[:12], + loginuid=loginuid) events = [ Event(process=touch, event_type=EventType.CREATION, file=fut, host_path=''), @@ -53,9 +53,6 @@ def test_chown(fact, test_container, server): host_path='', owner_uid=TEST_UID, owner_gid=TEST_GID), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events) @@ -89,13 +86,13 @@ def test_multiple(fact, test_container, server): container_id=test_container.id[:12], loginuid=loginuid) chown = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chown', - args=chown_cmd, - name='chown', - container_id=test_container.id[:12], - loginuid=loginuid) + uid=0, + gid=0, + exe_path='/usr/bin/chown', + args=chown_cmd, + name='chown', + container_id=test_container.id[:12], + loginuid=loginuid) events.extend([ Event(process=touch, event_type=EventType.CREATION, file=fut, @@ -104,9 +101,6 @@ def test_multiple(fact, test_container, server): host_path='', owner_uid=TEST_UID, owner_gid=TEST_GID), ]) - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events) @@ -195,9 +189,6 @@ def test_ignored(fact, test_container, server): for e in ignored_events: print(f'Events that should be ignored: {e}') - for e in expected_events: - print(f'Waiting for event: {e}') - server.wait_events(events=expected_events, ignored=ignored_events) @@ -252,17 +243,13 @@ def test_no_change(fact, test_container, server): container_id=test_container.id[:12], loginuid=loginuid) ] - + # Expect both chown events (all calls to chown trigger events) events = [ Event(process=touch, event_type=EventType.CREATION, file=fut, host_path=''), *(Event(process=p, event_type=EventType.OWNERSHIP, file=fut, - host_path='', owner_uid=TEST_UID, owner_gid=TEST_GID) for p in chown), + host_path='', owner_uid=TEST_UID, owner_gid=TEST_GID) for p in chown), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events) - diff --git a/tests/test_path_unlink.py b/tests/test_path_unlink.py index 3a7cde5b..7cf9dd5c 100644 --- a/tests/test_path_unlink.py +++ b/tests/test_path_unlink.py @@ -85,7 +85,6 @@ def test_ignored(fact, test_file, ignored_dir, server): e = Event(process=process, event_type=EventType.UNLINK, file=test_file, host_path=test_file) - print(f'Waiting for event: {e}') server.wait_events([e], ignored=[ignored_event]) @@ -118,7 +117,6 @@ def test_external_process(fact, monitored_dir, server): removal = Event(process=process, event_type=EventType.UNLINK, file=fut, host_path='') - print(f'Waiting for event: {removal}') try: server.wait_events([removal]) @@ -161,9 +159,6 @@ def test_overlay(fact, test_container, server): file=fut, host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events) @@ -199,9 +194,6 @@ def test_mounted_dir(fact, test_container, ignored_dir, server): host_path=''), ] - for e in events: - print(f'Waiting for event: {e}') - server.wait_events(events) @@ -222,6 +214,5 @@ def test_unmonitored_mounted_dir(fact, test_container, test_file, server): loginuid=pow(2, 32)-1) event = Event(process=process, event_type=EventType.UNLINK, file=fut, host_path=test_file) - print(f'Waiting for event: {event}') server.wait_events([event]) From cdba3123a6de281d1d539d94a7ab5eeb7b1f3a6d Mon Sep 17 00:00:00 2001 From: Mauro Ezequiel Moltrasio Date: Mon, 2 Feb 2026 16:20:30 +0100 Subject: [PATCH 2/3] chore(tests): leverage autouse for fact fixture With the addition of the autouse feature to the fact fixture the fact container is spin up and torn down on its own for every test, no need to declare explicitly. --- tests/test_file_open.py | 21 ++++++++------------- tests/test_misc.py | 2 +- tests/test_path_chmod.py | 21 +++++++-------------- tests/test_path_chown.py | 12 ++++-------- tests/test_path_unlink.py | 18 +++++++----------- 5 files changed, 27 insertions(+), 47 deletions(-) diff --git a/tests/test_file_open.py b/tests/test_file_open.py index dac8eedf..7636ef83 100644 --- a/tests/test_file_open.py +++ b/tests/test_file_open.py @@ -4,13 +4,12 @@ from event import Event, EventType, Process -def test_open(fact, monitored_dir, server): +def test_open(monitored_dir, server): """ Tests the opening of a file and verifies that the corresponding event is captured by the server. Args: - fact: Fixture for file activity (only required to be running). monitored_dir: Temporary directory path for creating the test file. server: The server instance to communicate with. """ @@ -25,13 +24,12 @@ def test_open(fact, monitored_dir, server): server.wait_events([e]) -def test_multiple(fact, monitored_dir, server): +def test_multiple(monitored_dir, server): """ Tests the opening of multiple files and verifies that the corresponding events are captured by the server. Args: - fact: Fixture for file activity (only required to be running). monitored_dir: Temporary directory path for creating the test file. server: The server instance to communicate with. """ @@ -49,13 +47,12 @@ def test_multiple(fact, monitored_dir, server): server.wait_events(events) -def test_multiple_access(fact, test_file, server): +def test_multiple_access(test_file, server): """ Tests multiple opening of a file and verifies that the corresponding events are captured by the server. Args: - fact: Fixture for file activity (only required to be running). monitored_dir: Temporary directory path for creating the test file. server: The server instance to communicate with. """ @@ -70,13 +67,12 @@ def test_multiple_access(fact, test_file, server): server.wait_events(events) -def test_ignored(fact, test_file, ignored_dir, server): +def test_ignored(test_file, ignored_dir, server): """ Tests that open events on ignored files are not captured by the server. Args: - fact: Fixture for file activity (only required to be running). test_file: Temporary file for testing. ignored_dir: Temporary directory path that is not monitored by fact. server: The server instance to communicate with. @@ -112,13 +108,12 @@ def do_test(fut: str, stop_event: mp.Event): stop_event.wait() -def test_external_process(fact, monitored_dir, server): +def test_external_process(monitored_dir, server): """ Tests the opening of a file by an external process and verifies that the corresponding event is captured by the server. Args: - fact: Fixture for file activity (only required to be running). monitored_dir: Temporary directory path for creating the test file. server: The server instance to communicate with. """ @@ -142,7 +137,7 @@ def test_external_process(fact, monitored_dir, server): proc.join(1) -def test_overlay(fact, test_container, server): +def test_overlay(test_container, server): # File Under Test fut = '/container-dir/test.txt' @@ -167,7 +162,7 @@ def test_overlay(fact, test_container, server): server.wait_events(events) -def test_mounted_dir(fact, test_container, ignored_dir, server): +def test_mounted_dir(test_container, ignored_dir, server): # File Under Test fut = '/mounted/test.txt' @@ -188,7 +183,7 @@ def test_mounted_dir(fact, test_container, ignored_dir, server): server.wait_events([event]) -def test_unmonitored_mounted_dir(fact, test_container, test_file, server): +def test_unmonitored_mounted_dir(test_container, test_file, server): # File Under Test fut = '/unmonitored/test.txt' diff --git a/tests/test_misc.py b/tests/test_misc.py index 8b89c43b..edc63067 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -40,7 +40,7 @@ def run_self_deleter(fact, monitored_dir, logs_dir, docker_client, build_self_de container.remove() -def test_d_path_sanitization(fact, monitored_dir, server, run_self_deleter, docker_client): +def test_d_path_sanitization(monitored_dir, server, run_self_deleter, docker_client): """ Ensure the sanitization of paths obtained by calling the bpf_d_path helper don't include the " (deleted)" suffix when the file is diff --git a/tests/test_path_chmod.py b/tests/test_path_chmod.py index 69299838..2f0c2b93 100644 --- a/tests/test_path_chmod.py +++ b/tests/test_path_chmod.py @@ -4,13 +4,12 @@ from event import Event, EventType, Process -def test_chmod(fact, monitored_dir, server): +def test_chmod(monitored_dir, server): """ Tests changing permissions on a file and verifies the corresponding event is captured by the server Args: - fact: Fixture for file activity (only required to be runing). monitored_dir: Temporary directory path for creating the test file. server: The server instance to communicate with. """ @@ -25,12 +24,11 @@ def test_chmod(fact, monitored_dir, server): server.wait_events([e]) -def test_multiple(fact, monitored_dir, server): +def test_multiple(monitored_dir, server): """ Tests modifying permissions on multiple files. Args: - fact: Fixture for file activity (only required to be runing). monitored_dir: Temporary directory path for creating the test file. server: The server instance to communicate with. """ @@ -54,12 +52,11 @@ def test_multiple(fact, monitored_dir, server): server.wait_events(events) -def test_ignored(fact, test_file, ignored_dir, server): +def test_ignored(test_file, ignored_dir, server): """ Tests that permission events on ignored files are not captured. Args: - fact: Fixture for file activity (only required to be running). test_file: File monitored on the host, mounted to the container. ignored_dir: Temporary directory path that is not monitored by fact. server: The server instance to communicate with. @@ -95,13 +92,12 @@ def do_test(fut: str, mode: int, stop_event: mp.Event): stop_event.wait() -def test_external_process(fact, monitored_dir, server): +def test_external_process(monitored_dir, server): """ Tests permission change of a file by an external process and verifies that the corresponding event is captured by the server. Args: - fact: Fixture for file activity (only required to be running). monitored_dir: Temporary directory path for creating the test file. server: The server instance to communicate with. """ @@ -123,12 +119,11 @@ def test_external_process(fact, monitored_dir, server): proc.join(1) -def test_overlay(fact, test_container, server): +def test_overlay(test_container, server): """ Test permission changes on an overlayfs file (inside a container) Args: - fact: Fixture for file activity (only required to be running). test_container: A container for running commands in. server: The server instance to communicate with. """ @@ -169,12 +164,11 @@ def test_overlay(fact, test_container, server): server.wait_events(events) -def test_mounted_dir(fact, test_container, ignored_dir, server): +def test_mounted_dir(test_container, ignored_dir, server): """ Test permission changes on a file bind mounted into a container Args: - fact: Fixture for file activity (only required to be running). test_container: A container for running commands in. ignored_dir: This directory is ignored on the host, and mounted to the container. server: The server instance to communicate with. @@ -214,13 +208,12 @@ def test_mounted_dir(fact, test_container, ignored_dir, server): server.wait_events(events) -def test_unmonitored_mounted_dir(fact, test_container, test_file, server): +def test_unmonitored_mounted_dir(test_container, test_file, server): """ Test permission changes on a file bind mounted to a container and monitored on the host. Args: - fact: Fixture for file activity (only required to be running). test_container: A container for running commands in. test_file: File monitored on the host, mounted to the container. server: The server instance to communicate with. diff --git a/tests/test_path_chown.py b/tests/test_path_chown.py index 3ae09974..d15d842c 100644 --- a/tests/test_path_chown.py +++ b/tests/test_path_chown.py @@ -10,13 +10,12 @@ TEST_GID = 2345 -def test_chown(fact, test_container, server): +def test_chown(test_container, server): """ Execute a chown operation on a file and verifies the corresponding event is captured by the server. Args: - fact: Fixture for file activity (only required to be running). test_container: A container for running commands in. server: The server instance to communicate with. """ @@ -56,13 +55,12 @@ def test_chown(fact, test_container, server): server.wait_events(events) -def test_multiple(fact, test_container, server): +def test_multiple(test_container, server): """ Tests ownership operations on multiple files and verifies the corresponding events are captured by the server. Args: - fact: Fixture for file activity (only required to be running). test_container: A container for running commands in. server: The server instance to communicate with. """ @@ -104,13 +102,12 @@ def test_multiple(fact, test_container, server): server.wait_events(events) -def test_ignored(fact, test_container, server): +def test_ignored(test_container, server): """ Tests that ownership events on ignored files are not captured by the server. Args: - fact: Fixture for file activity (only required to be running). test_container: A container for running commands in. server: The server instance to communicate with. """ @@ -192,12 +189,11 @@ def test_ignored(fact, test_container, server): server.wait_events(events=expected_events, ignored=ignored_events) -def test_no_change(fact, test_container, server): +def test_no_change(test_container, server): """ Tests that chown to the same UID/GID triggers events for all calls. Args: - fact: Fixture for file activity (only required to be running). test_container: A container for running commands in. server: The server instance to communicate with. """ diff --git a/tests/test_path_unlink.py b/tests/test_path_unlink.py index 7cf9dd5c..04d6ae81 100644 --- a/tests/test_path_unlink.py +++ b/tests/test_path_unlink.py @@ -6,13 +6,12 @@ from event import Event, EventType, Process -def test_remove(fact, test_file, server): +def test_remove(test_file, server): """ Tests the removal of a file and verifies the corresponding event is captured by the server. Args: - fact: Fixture for file activity (only required to be running). test_file: Temporary file for testing. server: The server instance to communicate with. """ @@ -27,13 +26,12 @@ def test_remove(fact, test_file, server): server.wait_events(events) -def test_multiple(fact, monitored_dir, server): +def test_multiple(monitored_dir, server): """ Tests the removal of multiple files and verifies the corresponding events are captured by the server. Args: - fact: Fixture for file activity (only required to be running). monitored_dir: Temporary directory path for monitoring the test file. server: The server instance to communicate with. """ @@ -57,13 +55,12 @@ def test_multiple(fact, monitored_dir, server): server.wait_events(events) -def test_ignored(fact, test_file, ignored_dir, server): +def test_ignored(test_file, ignored_dir, server): """ Tests that unlink events on ignored files are not captured by the server. Args: - fact: Fixture for file activity (only required to be running). monitored_dir: Temporary directory path for creating the test file. ignored_dir: Temporary directory path that is not monitored by fact. server: The server instance to communicate with. @@ -98,13 +95,12 @@ def do_test(fut: str, stop_event: mp.Event): stop_event.wait() -def test_external_process(fact, monitored_dir, server): +def test_external_process(monitored_dir, server): """ Tests the removal of a file by an external process and verifies that the corresponding event is captured by the server. Args: - fact: Fixture for file activity (only required to be running). monitored_dir: Temporary directory path for creating the test file. server: The server instance to communicate with. """ @@ -125,7 +121,7 @@ def test_external_process(fact, monitored_dir, server): proc.join(1) -def test_overlay(fact, test_container, server): +def test_overlay(test_container, server): # File Under Test fut = '/container-dir/test.txt' @@ -162,7 +158,7 @@ def test_overlay(fact, test_container, server): server.wait_events(events) -def test_mounted_dir(fact, test_container, ignored_dir, server): +def test_mounted_dir(test_container, ignored_dir, server): # File Under Test fut = '/mounted/test.txt' @@ -197,7 +193,7 @@ def test_mounted_dir(fact, test_container, ignored_dir, server): server.wait_events(events) -def test_unmonitored_mounted_dir(fact, test_container, test_file, server): +def test_unmonitored_mounted_dir(test_container, test_file, server): # File Under Test fut = '/unmonitored/test.txt' From 0d686bb8723b81275ecc57ebe85ca66d92136d60 Mon Sep 17 00:00:00 2001 From: Mauro Ezequiel Moltrasio Date: Mon, 2 Feb 2026 17:00:29 +0100 Subject: [PATCH 3/3] feat(tests): make restrict mode the default, use Process.in_container This change replaces the ignored events for strict mode, this is more reliable, since a change to how we report events could cause us to miss the ignored event if it is reported differently. Instead, strict mode will cause tests to fail if any event that is not expected is found. We also use the new class method `Process.in_container` to simplify the definition of processes that run inside containers. --- tests/server.py | 10 +- tests/test_config_hotreload.py | 18 +--- tests/test_file_open.py | 48 ++++----- tests/test_misc.py | 14 ++- tests/test_path_chmod.py | 88 +++++++-------- tests/test_path_chown.py | 190 ++++++++++++--------------------- tests/test_path_unlink.py | 88 +++++++-------- 7 files changed, 173 insertions(+), 283 deletions(-) diff --git a/tests/server.py b/tests/server.py index eb1d2baf..d3aa8d15 100644 --- a/tests/server.py +++ b/tests/server.py @@ -81,7 +81,7 @@ def is_running(self): """ return self.running.is_set() - def _wait_events(self, events: list[Event], ignored: list[Event], strict: bool): + def _wait_events(self, events: list[Event], strict: bool): while self.is_running(): msg = self.get_next() if msg is None: @@ -89,9 +89,6 @@ def _wait_events(self, events: list[Event], ignored: list[Event], strict: bool): continue print(f'Got event: {msg}') - if msg in ignored: - raise ValueError(f'Caught ignored event: {msg}') - if msg in events: events.remove(msg) if len(events) == 0: @@ -99,7 +96,7 @@ def _wait_events(self, events: list[Event], ignored: list[Event], strict: bool): elif strict: raise ValueError(f'Encountered unexpected event: {msg}') - def wait_events(self, events: list[Event], ignored: list[Event] = [], strict: bool = False): + def wait_events(self, events: list[Event], strict: bool = True): """ Continuously checks the server for incoming events until the specified events are found. @@ -107,12 +104,11 @@ def wait_events(self, events: list[Event], ignored: list[Event] = [], strict: bo Args: server: The server instance to retrieve events from. event (list[Event]): The events to search for. - ignored (list[Event]): List of events that should not happen. strict (bool): Fail if an unexpected event is detected. Raises: TimeoutError: If the required events are not found in 5 seconds. """ print('Waiting for events:', *events, sep='\n') - fs = self.executor.submit(self._wait_events, events, ignored, strict) + fs = self.executor.submit(self._wait_events, events, strict) fs.result(timeout=5) diff --git a/tests/test_config_hotreload.py b/tests/test_config_hotreload.py index e47f776d..9a875228 100644 --- a/tests/test_config_hotreload.py +++ b/tests/test_config_hotreload.py @@ -125,10 +125,6 @@ def test_paths(fact, fact_config, monitored_dir, ignored_dir, server): with open(ignored_file, 'w') as f: f.write('This is to be ignored') - ignored_event = Event(process=p, event_type=EventType.CREATION, - file=ignored_file, host_path='') - print(f'Ignoring: {ignored_event}') - # File Under Test fut = os.path.join(monitored_dir, 'test2.txt') with open(fut, 'w') as f: @@ -137,7 +133,7 @@ def test_paths(fact, fact_config, monitored_dir, ignored_dir, server): e = Event(process=p, event_type=EventType.CREATION, file=fut, host_path='') - server.wait_events([e], ignored=[ignored_event]) + server.wait_events([e]) config, config_file = fact_config config['paths'] = [ignored_dir] @@ -155,11 +151,7 @@ def test_paths(fact, fact_config, monitored_dir, ignored_dir, server): with open(fut, 'w') as f: f.write('This is another ignored event') - ignored_event = Event( - process=p, event_type=EventType.OPEN, file=fut, host_path='') - print(f'Ignoring: {ignored_event}') - - server.wait_events([e], ignored=[ignored_event]) + server.wait_events([e]) def test_paths_addition(fact, fact_config, monitored_dir, ignored_dir, server): @@ -170,10 +162,6 @@ def test_paths_addition(fact, fact_config, monitored_dir, ignored_dir, server): with open(ignored_file, 'w') as f: f.write('This is to be ignored') - ignored_event = Event(process=p, event_type=EventType.CREATION, - file=ignored_file, host_path='') - print(f'Ignoring: {ignored_event}') - # File Under Test fut = os.path.join(monitored_dir, 'test2.txt') with open(fut, 'w') as f: @@ -182,7 +170,7 @@ def test_paths_addition(fact, fact_config, monitored_dir, ignored_dir, server): e = Event(process=p, event_type=EventType.CREATION, file=fut, host_path='') - server.wait_events([e], ignored=[ignored_event]) + server.wait_events([e]) config, config_file = fact_config config['paths'] = [monitored_dir, ignored_dir] diff --git a/tests/test_file_open.py b/tests/test_file_open.py index 7636ef83..cc14b585 100644 --- a/tests/test_file_open.py +++ b/tests/test_file_open.py @@ -84,10 +84,6 @@ def test_ignored(test_file, ignored_dir, server): with open(ignored_file, 'w') as f: f.write('This is to be ignored') - ignored_event = Event(process=p, event_type=EventType.CREATION, - file=ignored_file, host_path='') - print(f'Ignoring: {ignored_event}') - # File Under Test with open(test_file, 'w') as f: f.write('This is a test') @@ -95,7 +91,7 @@ def test_ignored(test_file, ignored_dir, server): e = Event(process=p, event_type=EventType.OPEN, file=test_file, host_path=test_file) - server.wait_events([e], ignored=[ignored_event]) + server.wait_events([e]) def do_test(fut: str, stop_event: mp.Event): @@ -144,14 +140,12 @@ def test_overlay(test_container, server): # Create the exec and an equivalent event that it will trigger test_container.exec_run(f'touch {fut}') - process = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=f'touch {fut}', - name='touch', - container_id=test_container.id[:12], - loginuid=pow(2, 32)-1) + process = Process.in_container( + exe_path='/usr/bin/touch', + args=f'touch {fut}', + name='touch', + container_id=test_container.id[:12], + ) events = [ Event(process=process, event_type=EventType.CREATION, file=fut, host_path=''), @@ -169,14 +163,12 @@ def test_mounted_dir(test_container, ignored_dir, server): # Create the exec and an equivalent event that it will trigger test_container.exec_run(f'touch {fut}') - process = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=f'touch {fut}', - name='touch', - container_id=test_container.id[:12], - loginuid=pow(2, 32)-1) + process = Process.in_container( + exe_path='/usr/bin/touch', + args=f'touch {fut}', + name='touch', + container_id=test_container.id[:12], + ) event = Event(process=process, event_type=EventType.CREATION, file=fut, host_path='') @@ -190,14 +182,12 @@ def test_unmonitored_mounted_dir(test_container, test_file, server): # Create the exec and an equivalent event that it will trigger test_container.exec_run(f'touch {fut}') - process = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=f'touch {fut}', - name='touch', - container_id=test_container.id[:12], - loginuid=pow(2, 32)-1) + process = Process.in_container( + exe_path='/usr/bin/touch', + args=f'touch {fut}', + name='touch', + container_id=test_container.id[:12], + ) event = Event(process=process, event_type=EventType.OPEN, file=fut, host_path=test_file) diff --git a/tests/test_misc.py b/tests/test_misc.py index edc63067..a18814a4 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -52,14 +52,12 @@ def test_d_path_sanitization(monitored_dir, server, run_self_deleter, docker_cli container = run_self_deleter - process = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/local/bin/self-deleter', - args=f'self-deleter {fut}', - name='self-deleter', - container_id=container.id[:12], - loginuid=pow(2, 32)-1) + process = Process.in_container( + exe_path='/usr/local/bin/self-deleter', + args=f'self-deleter {fut}', + name='self-deleter', + container_id=container.id[:12], + ) event = Event(process=process, event_type=EventType.OPEN, file=fut, host_path=host_path) diff --git a/tests/test_path_chmod.py b/tests/test_path_chmod.py index 2f0c2b93..a4fd6345 100644 --- a/tests/test_path_chmod.py +++ b/tests/test_path_chmod.py @@ -70,17 +70,13 @@ def test_ignored(test_file, ignored_dir, server): f.write('This is to be ignored') os.chmod(ignored_file, mode) - ignored_event = Event(process=process, event_type=EventType.PERMISSION, - file=ignored_file, host_path='', mode=mode) - print(f'Ignoring: {ignored_event}') - # File Under Test os.chmod(test_file, mode) e = Event(process=process, event_type=EventType.PERMISSION, file=test_file, host_path=test_file, mode=mode) - server.wait_events([e], ignored=[ignored_event]) + server.wait_events([e]) def do_test(fut: str, mode: int, stop_event: mp.Event): @@ -109,11 +105,15 @@ def test_external_process(monitored_dir, server): proc.start() process = Process.from_proc(proc.pid) - event = Event(process=process, event_type=EventType.PERMISSION, - file=fut, host_path='', mode=mode) + events = [ + Event(process=process, event_type=EventType.CREATION, + file=fut, host_path='', mode=mode), + Event(process=process, event_type=EventType.PERMISSION, + file=fut, host_path='', mode=mode), + ] try: - server.wait_events([event]) + server.wait_events(events) finally: stop_event.set() proc.join(1) @@ -135,23 +135,18 @@ def test_overlay(test_container, server): test_container.exec_run(f'touch {fut}') test_container.exec_run(f'chmod {mode} {fut}') - loginuid = pow(2, 32)-1 - touch = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=f'touch {fut}', - name='touch', - container_id=test_container.id[:12], - loginuid=loginuid) - chmod = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chmod', - args=f'chmod {mode} {fut}', - name='chmod', - container_id=test_container.id[:12], - loginuid=loginuid) + touch = Process.in_container( + exe_path='/usr/bin/touch', + args=f'touch {fut}', + name='touch', + container_id=test_container.id[:12], + ) + chmod = Process.in_container( + exe_path='/usr/bin/chmod', + args=f'chmod {mode} {fut}', + name='chmod', + container_id=test_container.id[:12], + ) events = [ Event(process=touch, event_type=EventType.CREATION, file=fut, host_path=''), @@ -181,23 +176,18 @@ def test_mounted_dir(test_container, ignored_dir, server): test_container.exec_run(f'touch {fut}') test_container.exec_run(f'chmod {mode} {fut}') - loginuid = pow(2, 32)-1 - touch = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=f'touch {fut}', - name='touch', - container_id=test_container.id[:12], - loginuid=loginuid) - chmod = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chmod', - args=f'chmod {mode} {fut}', - name='chmod', - container_id=test_container.id[:12], - loginuid=loginuid) + touch = Process.in_container( + exe_path='/usr/bin/touch', + args=f'touch {fut}', + name='touch', + container_id=test_container.id[:12], + ) + chmod = Process.in_container( + exe_path='/usr/bin/chmod', + args=f'chmod {mode} {fut}', + name='chmod', + container_id=test_container.id[:12], + ) events = [ Event(process=touch, event_type=EventType.CREATION, file=fut, host_path=''), @@ -227,14 +217,12 @@ def test_unmonitored_mounted_dir(test_container, test_file, server): # Create the exec and an equivalent event that it will trigger test_container.exec_run(f'chmod {mode} {fut}') - process = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chmod', - args=f'chmod {mode} {fut}', - name='chmod', - container_id=test_container.id[:12], - loginuid=pow(2, 32)-1) + process = Process.in_container( + exe_path='/usr/bin/chmod', + args=f'chmod {mode} {fut}', + name='chmod', + container_id=test_container.id[:12], + ) event = Event(process=process, event_type=EventType.PERMISSION, file=fut, host_path=test_file, mode=int(mode, 8)) diff --git a/tests/test_path_chown.py b/tests/test_path_chown.py index d15d842c..a1ade331 100644 --- a/tests/test_path_chown.py +++ b/tests/test_path_chown.py @@ -28,26 +28,23 @@ def test_chown(test_container, server): test_container.exec_run(touch_cmd) test_container.exec_run(chown_cmd) - loginuid = pow(2, 32) - 1 - touch = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=touch_cmd, - name='touch', - container_id=test_container.id[:12], - loginuid=loginuid) - chown = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chown', - args=chown_cmd, - name='chown', - container_id=test_container.id[:12], - loginuid=loginuid) + touch = Process.in_container( + exe_path='/usr/bin/touch', + args=touch_cmd, + name='touch', + container_id=test_container.id[:12], + ) + chown = Process.in_container( + exe_path='/usr/bin/chown', + args=chown_cmd, + name='chown', + container_id=test_container.id[:12], + ) events = [ Event(process=touch, event_type=EventType.CREATION, file=fut, host_path=''), + Event(process=touch, event_type=EventType.OPEN, file=fut, + host_path=''), Event(process=chown, event_type=EventType.OWNERSHIP, file=fut, host_path='', owner_uid=TEST_UID, owner_gid=TEST_GID), ] @@ -65,7 +62,6 @@ def test_multiple(test_container, server): server: The server instance to communicate with. """ events = [] - loginuid = pow(2, 32) - 1 # File Under Test for i in range(3): @@ -75,26 +71,24 @@ def test_multiple(test_container, server): test_container.exec_run(touch_cmd) test_container.exec_run(chown_cmd) - touch = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=touch_cmd, - name='touch', - container_id=test_container.id[:12], - loginuid=loginuid) - chown = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chown', - args=chown_cmd, - name='chown', - container_id=test_container.id[:12], - loginuid=loginuid) + touch = Process.in_container( + exe_path='/usr/bin/touch', + args=touch_cmd, + name='touch', + container_id=test_container.id[:12], + ) + chown = Process.in_container( + exe_path='/usr/bin/chown', + args=chown_cmd, + name='chown', + container_id=test_container.id[:12], + ) events.extend([ Event(process=touch, event_type=EventType.CREATION, file=fut, host_path=''), + Event(process=touch, event_type=EventType.OPEN, file=fut, + host_path=''), Event(process=chown, event_type=EventType.OWNERSHIP, file=fut, host_path='', owner_uid=TEST_UID, owner_gid=TEST_GID), ]) @@ -111,8 +105,6 @@ def test_ignored(test_container, server): test_container: A container for running commands in. server: The server instance to communicate with. """ - loginuid = pow(2, 32) - 1 - ignored_file = '/test.txt' monitored_file = '/container-dir/test.txt' @@ -126,67 +118,28 @@ def test_ignored(test_container, server): test_container.exec_run(monitored_touch_cmd) test_container.exec_run(monitored_chown_cmd) - ignored_touch = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=ignored_touch_cmd, - name='touch', - container_id=test_container.id[:12], - loginuid=loginuid) - ignored_chown = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chown', - args=ignored_chown_cmd, - name='chown', - container_id=test_container.id[:12], - loginuid=loginuid) - reported_touch = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=monitored_touch_cmd, - name='touch', - container_id=test_container.id[:12], - loginuid=loginuid) - reported_chown = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chown', - args=monitored_chown_cmd, - name='chown', - container_id=test_container.id[:12], - loginuid=loginuid) - ignored_events = [ - Event(process=ignored_touch, - event_type=EventType.CREATION, - file=ignored_file, - host_path=''), - Event(process=ignored_chown, - event_type=EventType.OWNERSHIP, - file=ignored_file, - host_path='', - owner_uid=TEST_UID, - owner_gid=TEST_GID), - ] - expected_events = [ - Event(process=reported_touch, - event_type=EventType.CREATION, - file=monitored_file, - host_path=''), - Event(process=reported_chown, - event_type=EventType.OWNERSHIP, - file=monitored_file, - host_path='', - owner_uid=TEST_UID, - owner_gid=TEST_GID), + reported_touch = Process.in_container( + exe_path='/usr/bin/touch', + args=monitored_touch_cmd, + name='touch', + container_id=test_container.id[:12], + ) + reported_chown = Process.in_container( + exe_path='/usr/bin/chown', + args=monitored_chown_cmd, + name='chown', + container_id=test_container.id[:12], + ) + events = [ + Event(process=reported_touch, event_type=EventType.CREATION, + file=monitored_file, host_path=''), + Event(process=reported_touch, event_type=EventType.OPEN, + file=monitored_file, host_path=''), + Event(process=reported_chown, event_type=EventType.OWNERSHIP, + file=monitored_file, host_path='', owner_uid=TEST_UID, owner_gid=TEST_GID), ] - for e in ignored_events: - print(f'Events that should be ignored: {e}') - - server.wait_events(events=expected_events, ignored=ignored_events) + server.wait_events(events=events) def test_no_change(test_container, server): @@ -212,40 +165,29 @@ def test_no_change(test_container, server): # Second chown to the same UID/GID - this should ALSO trigger an event test_container.exec_run(chown_cmd) - loginuid = pow(2, 32) - 1 - touch = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=touch_cmd, - name='touch', - container_id=test_container.id[:12], - loginuid=loginuid) - chown = [ - Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chown', - args=chown_cmd, - name='chown', - container_id=test_container.id[:12], - loginuid=loginuid), - Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/chown', - args=chown_cmd, - name='chown', - container_id=test_container.id[:12], - loginuid=loginuid) - ] + touch = Process.in_container( + exe_path='/usr/bin/touch', + args=touch_cmd, + name='touch', + container_id=test_container.id[:12], + ) + chown = Process.in_container( + exe_path='/usr/bin/chown', + args=chown_cmd, + name='chown', + container_id=test_container.id[:12], + ) + chown_event = Event(process=chown, event_type=EventType.OWNERSHIP, + file=fut, host_path='', owner_uid=TEST_UID, owner_gid=TEST_GID) # Expect both chown events (all calls to chown trigger events) events = [ Event(process=touch, event_type=EventType.CREATION, file=fut, host_path=''), - *(Event(process=p, event_type=EventType.OWNERSHIP, file=fut, - host_path='', owner_uid=TEST_UID, owner_gid=TEST_GID) for p in chown), + Event(process=touch, event_type=EventType.OPEN, file=fut, + host_path=''), + chown_event, + chown_event, ] server.wait_events(events) diff --git a/tests/test_path_unlink.py b/tests/test_path_unlink.py index 04d6ae81..08f46228 100644 --- a/tests/test_path_unlink.py +++ b/tests/test_path_unlink.py @@ -73,17 +73,13 @@ def test_ignored(test_file, ignored_dir, server): f.write('This is to be ignored') os.remove(ignored_file) - ignored_event = Event(process=process, event_type=EventType.UNLINK, - file=ignored_file, host_path='') - print(f'Ignoring: {ignored_event}') - # File Under Test os.remove(test_file) e = Event(process=process, event_type=EventType.UNLINK, file=test_file, host_path=test_file) - server.wait_events([e], ignored=[ignored_event]) + server.wait_events([e]) def do_test(fut: str, stop_event: mp.Event): @@ -111,11 +107,15 @@ def test_external_process(monitored_dir, server): proc.start() process = Process.from_proc(proc.pid) - removal = Event(process=process, event_type=EventType.UNLINK, - file=fut, host_path='') + events = [ + Event(process=process, event_type=EventType.CREATION, + file=fut, host_path=''), + Event(process=process, event_type=EventType.UNLINK, + file=fut, host_path=''), + ] try: - server.wait_events([removal]) + server.wait_events(events) finally: stop_event.set() proc.join(1) @@ -129,23 +129,18 @@ def test_overlay(test_container, server): test_container.exec_run(f'touch {fut}') test_container.exec_run(f'rm {fut}') - loginuid = pow(2, 32)-1 - touch = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=f'touch {fut}', - name='touch', - container_id=test_container.id[:12], - loginuid=loginuid) - rm = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/rm', - args=f'rm {fut}', - name='rm', - container_id=test_container.id[:12], - loginuid=loginuid) + touch = Process.in_container( + exe_path='/usr/bin/touch', + args=f'touch {fut}', + name='touch', + container_id=test_container.id[:12], + ) + rm = Process.in_container( + exe_path='/usr/bin/rm', + args=f'rm {fut}', + name='rm', + container_id=test_container.id[:12], + ) events = [ Event(process=touch, event_type=EventType.CREATION, file=fut, host_path=''), @@ -166,23 +161,18 @@ def test_mounted_dir(test_container, ignored_dir, server): test_container.exec_run(f'touch {fut}') test_container.exec_run(f'rm {fut}') - loginuid = pow(2, 32)-1 - touch = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/touch', - args=f'touch {fut}', - name='touch', - container_id=test_container.id[:12], - loginuid=loginuid) - rm = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/rm', - args=f'rm {fut}', - name='rm', - container_id=test_container.id[:12], - loginuid=loginuid) + touch = Process.in_container( + exe_path='/usr/bin/touch', + args=f'touch {fut}', + name='touch', + container_id=test_container.id[:12], + ) + rm = Process.in_container( + exe_path='/usr/bin/rm', + args=f'rm {fut}', + name='rm', + container_id=test_container.id[:12], + ) events = [ Event(process=touch, event_type=EventType.CREATION, file=fut, host_path=''), @@ -200,14 +190,12 @@ def test_unmonitored_mounted_dir(test_container, test_file, server): # Create the exec and an equivalent event that it will trigger test_container.exec_run(f'rm {fut}') - process = Process(pid=None, - uid=0, - gid=0, - exe_path='/usr/bin/rm', - args=f'rm {fut}', - name='rm', - container_id=test_container.id[:12], - loginuid=pow(2, 32)-1) + process = Process.in_container( + exe_path='/usr/bin/rm', + args=f'rm {fut}', + name='rm', + container_id=test_container.id[:12], + ) event = Event(process=process, event_type=EventType.UNLINK, file=fut, host_path=test_file)