diff --git a/src/borg/testsuite/__init__.py b/src/borg/testsuite/__init__.py index d8df3e111..5c3a0a8f4 100644 --- a/src/borg/testsuite/__init__.py +++ b/src/borg/testsuite/__init__.py @@ -18,6 +18,7 @@ import unittest from ..xattr import get_all from ..platform import get_flags +from ..platformflags import is_win32 from ..helpers import umount from ..helpers import EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR from .. import platform @@ -66,6 +67,14 @@ def unopened_tempfile(): yield os.path.join(tempdir, "file") +def is_root(): + """return True if running with high privileges, like as root""" + if is_win32: + return False # TODO + else: + return os.getuid() == 0 + + @functools.lru_cache def are_symlinks_supported(): with unopened_tempfile() as filepath: diff --git a/src/borg/testsuite/archiver/create_cmd.py b/src/borg/testsuite/archiver/create_cmd.py index e7f1d4b0e..04d9d8fb7 100644 --- a/src/borg/testsuite/archiver/create_cmd.py +++ b/src/borg/testsuite/archiver/create_cmd.py @@ -25,6 +25,7 @@ from .. import ( is_utime_fully_supported, is_birthtime_fully_supported, same_ts_ns, + is_root, ) from . import ( ArchiverTestCaseBase, @@ -219,6 +220,7 @@ class ArchiverTestCase(ArchiverTestCaseBase): assert "input/file2" in out assert "input/file3" in out + @pytest.mark.skipif(is_root(), reason="test must not be run as (fake)root") def test_create_no_permission_file(self): file_path = os.path.join(self.input_path, "file") self.create_regular_file(file_path + "1", size=1000) @@ -228,6 +230,7 @@ class ArchiverTestCase(ArchiverTestCaseBase): if is_win32: subprocess.run(["icacls.exe", file_path + "2", "/deny", "everyone:(R)"]) else: + # note: this will NOT take away read permissions for root os.chmod(file_path + "2", 0o000) self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION) flist = "".join(f"input/file{n}\n" for n in range(1, 4))