forked from p15670423/monkey
UT: Move Linux directory permissions check to a utility function
This commit is contained in:
parent
b9efc2d552
commit
3c1e25b88c
|
@ -7,6 +7,9 @@ if is_windows_os():
|
||||||
FULL_CONTROL = 2032127
|
FULL_CONTROL = 2032127
|
||||||
ACE_ACCESS_MODE_GRANT_ACCESS = win32security.GRANT_ACCESS
|
ACE_ACCESS_MODE_GRANT_ACCESS = win32security.GRANT_ACCESS
|
||||||
ACE_INHERIT_OBJECT_AND_CONTAINER = 3
|
ACE_INHERIT_OBJECT_AND_CONTAINER = 3
|
||||||
|
else:
|
||||||
|
import os
|
||||||
|
import stat
|
||||||
|
|
||||||
|
|
||||||
def _get_acl_and_sid_from_path(path: str):
|
def _get_acl_and_sid_from_path(path: str):
|
||||||
|
@ -33,3 +36,12 @@ def assert_windows_permissions(path: str):
|
||||||
assert ace_sid == user_sid
|
assert ace_sid == user_sid
|
||||||
assert ace_permissions == FULL_CONTROL and ace_access_mode == ACE_ACCESS_MODE_GRANT_ACCESS
|
assert ace_permissions == FULL_CONTROL and ace_access_mode == ACE_ACCESS_MODE_GRANT_ACCESS
|
||||||
assert ace_inheritance == ACE_INHERIT_OBJECT_AND_CONTAINER
|
assert ace_inheritance == ACE_INHERIT_OBJECT_AND_CONTAINER
|
||||||
|
|
||||||
|
|
||||||
|
def assert_linux_permissions(path: str):
|
||||||
|
st = os.stat(path)
|
||||||
|
|
||||||
|
expected_mode = stat.S_IRWXU
|
||||||
|
actual_mode = st.st_mode & (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
|
||||||
|
|
||||||
|
assert expected_mode == actual_mode
|
||||||
|
|
|
@ -2,7 +2,7 @@ import os
|
||||||
import stat
|
import stat
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from tests.monkey_island.utils import assert_windows_permissions
|
from tests.monkey_island.utils import assert_linux_permissions, assert_windows_permissions
|
||||||
|
|
||||||
from monkey_island.cc.server_utils.file_utils import (
|
from monkey_island.cc.server_utils.file_utils import (
|
||||||
create_secure_directory,
|
create_secure_directory,
|
||||||
|
@ -39,12 +39,8 @@ def test_create_secure_directory__no_parent_dir(test_path_nested):
|
||||||
@pytest.mark.skipif(is_windows_os(), reason="Tests Posix (not Windows) permissions.")
|
@pytest.mark.skipif(is_windows_os(), reason="Tests Posix (not Windows) permissions.")
|
||||||
def test_create_secure_directory__perm_linux(test_path):
|
def test_create_secure_directory__perm_linux(test_path):
|
||||||
create_secure_directory(test_path)
|
create_secure_directory(test_path)
|
||||||
st = os.stat(test_path)
|
|
||||||
|
|
||||||
expected_mode = stat.S_IRWXU
|
assert_linux_permissions(test_path)
|
||||||
actual_mode = st.st_mode & (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
|
|
||||||
|
|
||||||
assert expected_mode == actual_mode
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not is_windows_os(), reason="Tests Windows (not Posix) permissions.")
|
@pytest.mark.skipif(not is_windows_os(), reason="Tests Windows (not Posix) permissions.")
|
||||||
|
|
Loading…
Reference in New Issue