From 169f346df8efc5bbcc33eda9859c4bb20fe471f4 Mon Sep 17 00:00:00 2001 From: Hongli Chen <94642294+Honglichenn@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:43:25 +0000 Subject: [PATCH] fix: set correct permission for the test directory. (#107) Signed-off-by: Hongli Chen --- .../integ/background/test_background_mode.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/openjd/adaptor_runtime/integ/background/test_background_mode.py b/test/openjd/adaptor_runtime/integ/background/test_background_mode.py index 7a51bb7..f62ff90 100644 --- a/test/openjd/adaptor_runtime/integ/background/test_background_mode.py +++ b/test/openjd/adaptor_runtime/integ/background/test_background_mode.py @@ -52,7 +52,18 @@ def mock_runtime_logger_level(self, tmpdir: pathlib.Path): @pytest.fixture def connection_file_path(self, tmp_path: pathlib.Path) -> str: - return os.path.join(tmp_path.absolute(), "connection.json") + connection_dir = os.path.join(tmp_path.absolute(), "connection_dir") + os.mkdir(connection_dir) + if OSName.is_windows(): + # In Windows, to prevent false positives in tests, it's crucial to remove the "Delete subfolders and files" + # permission from the parent folder. This step ensures that files cannot be deleted without explicit delete + # permissions, addressing an edge case where the same user owns both the parent folder and the file, + # bypassing delete permissions. `set_file_permissions_in_windows` will restrict the permission to read, + # write, delete current folder, which meets the requirement. + from openjd.adaptor_runtime._utils._secure_open import set_file_permissions_in_windows + + set_file_permissions_in_windows(connection_dir) + return os.path.join(connection_dir, "connection.json") @pytest.fixture def initialized_setup(