Skip to content

Commit

Permalink
check only others permissions for directories during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cwcummings committed Aug 9, 2023
1 parent c696bab commit a22e5d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a22e5d1

Please sign in to comment.