From a22e5d1967a476277bd15a42c06f0ee8ea3dac6c Mon Sep 17 00:00:00 2001 From: Charles-William Cummings Date: Wed, 9 Aug 2023 08:51:16 -0400 Subject: [PATCH] check only others permissions for directories during tests --- tests/test_filesystem.py | 4 ++-- tests/utils.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/test_filesystem.py b/tests/test_filesystem.py index 97b1f639..dda1395f 100644 --- a/tests/test_filesystem.py +++ b/tests/test_filesystem.py @@ -231,7 +231,7 @@ def test_public_wps_output_created(self): TestFileSystem.check_created_test_cases(output_file, hardlink_path) # Check that the hardlink's parent directory have the right permissions - utils.check_path_permissions(os.path.dirname(hardlink_path), 0o775) + utils.check_path_permissions(os.path.dirname(hardlink_path), 0o005, check_others_only=True) # A create event on a folder should not be processed (no corresponding target folder created) target_dir = os.path.join(filesystem_handler.get_wps_outputs_public_dir(), bird_name) @@ -466,7 +466,7 @@ def test_user_wps_output_created(self): TestFileSystem.check_created_test_cases(self.test_file, self.test_hardlink) # Check that the hardlink's parent directory has the right permissions - utils.check_path_permissions(os.path.dirname(self.test_hardlink), 0o777) + utils.check_path_permissions(os.path.dirname(self.test_hardlink), 0o007, check_others_only=True) # A create event on a folder should not be processed (no corresponding target folder created) subpath = str(self.job_id) diff --git a/tests/utils.py b/tests/utils.py index 6bbed766..599e188e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -712,12 +712,15 @@ def check_error_param_structure(body: JSON, check_val_equal(body["param"]["compare"], param_compare) -def check_path_permissions(path: Union[str, os.PathLike], permissions: int) -> None: +def check_path_permissions(path: Union[str, os.PathLike], permissions: int, check_others_only: bool = False) -> None: """ Checks if the path has the right permissions, by verifying the last digits of the octal permissions. """ - expected_perms = oct(permissions & 0o777) - actual_perms = oct(os.stat(path)[ST_MODE] & 0o777) + check_mask = 0o777 + if check_others_only: + check_mask = 0o007 + expected_perms = oct(permissions & check_mask) + actual_perms = oct(os.stat(path)[ST_MODE] & check_mask) try: assert actual_perms == expected_perms except AssertionError as err: