Add tests for Windows file permissions checking

This commit is contained in:
shreyamalviya 2021-06-09 16:01:47 +05:30 committed by Mike Salvatore
parent fcd758e24f
commit cd2f627cc1
1 changed files with 23 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import os
import pytest
import subprocess
from monkey_island.cc.server_utils import file_utils
@ -20,7 +21,7 @@ def test_expand_vars(patched_home_env):
@pytest.mark.skipif(os.name != "posix", reason="Tests Posix (not Windows) permissions.")
def test_has_expected_permissions_true(tmpdir, create_empty_file):
def test_has_expected_permissions_true_linux(tmpdir, create_empty_file):
file_name = f"{tmpdir}/test"
create_empty_file(file_name)
@ -30,10 +31,30 @@ def test_has_expected_permissions_true(tmpdir, create_empty_file):
@pytest.mark.skipif(os.name != "posix", reason="Tests Posix (not Windows) permissions.")
def test_has_expected_permissions_false(tmpdir, create_empty_file):
def test_has_expected_permissions_false_linux(tmpdir, create_empty_file):
file_name = f"{tmpdir}/test"
create_empty_file(file_name)
os.chmod(file_name, 0o755)
assert not file_utils.has_expected_permissions(file_name, 0o700)
@pytest.mark.skipif(os.name == "posix", reason="Tests Windows (not Posix) permissions.")
def test_has_expected_permissions_true_windows(tmpdir, create_empty_file):
file_name = f"{tmpdir}/test"
create_empty_file(file_name)
subprocess.run(f"echo y| cacls {file_name} /p %USERNAME%:F", shell=True)
assert file_utils.has_expected_permissions(file_name, 2032127)
@pytest.mark.skipif(os.name == "posix", reason="Tests Windows (not Posix) permissions.")
def test_has_expected_permissions_false_windows(tmpdir, create_empty_file):
file_name = f"{tmpdir}/test"
create_empty_file(file_name)
subprocess.run(f"echo y| cacls {file_name} /p %USERNAME%:R", shell=True)
assert not file_utils.has_expected_permissions(file_name, 2032127)