Skip to content

Commit ba0ea4c

Browse files
committed
Added parameterized UTF-8 tests
1 parent 6817ae0 commit ba0ea4c

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

tests/test_xattr.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import os
44

5+
import pytest
6+
57
from event import Event, EventType, Process
68
from server import FileActivityService
9+
from utils import join_path_with_filename, path_to_string
710

811

912
def test_setxattr(
@@ -204,3 +207,66 @@ def test_setxattr_new_file(
204207
],
205208
strict=False,
206209
)
210+
211+
212+
@pytest.mark.parametrize(
213+
'filename',
214+
[
215+
pytest.param('xattr.txt', id='ASCII'),
216+
pytest.param('café.txt', id='French'),
217+
pytest.param('файл.txt', id='Cyrillic'),
218+
pytest.param('测试.txt', id='Chinese'),
219+
pytest.param('🔒secure.txt', id='Emoji'),
220+
pytest.param(b'xattr\xff\xfe.txt', id='InvalidUTF8'),
221+
],
222+
)
223+
def test_setxattr_utf8_filenames(
224+
monitored_dir: str,
225+
server: FileActivityService,
226+
filename: str | bytes,
227+
):
228+
"""
229+
Tests that xattr events are correctly tracked on files with
230+
various UTF-8 and non-UTF-8 filenames.
231+
232+
Args:
233+
monitored_dir: Temporary directory path for creating the test file.
234+
server: The server instance to communicate with.
235+
filename: Name of the file to create (includes UTF-8 test cases).
236+
"""
237+
fut = join_path_with_filename(monitored_dir, filename)
238+
239+
with open(fut, 'w') as f:
240+
f.write('test')
241+
242+
# gRPC events use lossy UTF-8 conversion, but os.setxattr
243+
# needs the original path to find the file on disk.
244+
fut_str = path_to_string(fut)
245+
246+
process = Process.from_proc()
247+
248+
server.wait_events(
249+
[
250+
Event(
251+
process=process,
252+
event_type=EventType.CREATION,
253+
file=fut_str,
254+
host_path=fut_str,
255+
),
256+
],
257+
)
258+
259+
os.setxattr(fut, 'user.utf8_test', b'value')
260+
261+
server.wait_events(
262+
[
263+
Event(
264+
process=process,
265+
event_type=EventType.XATTR,
266+
file='',
267+
host_path=fut_str,
268+
xattr_name='user.utf8_test',
269+
),
270+
],
271+
strict=False,
272+
)

0 commit comments

Comments
 (0)