Просмотр исходного кода

skip "do not retry when permissions denied" test if running as root

we can not take away read permissions for root,
so the test would fail.
Thomas Waldmann 2 лет назад
Родитель
Сommit
2692fa1146
2 измененных файлов с 12 добавлено и 0 удалено
  1. 9 0
      src/borg/testsuite/__init__.py
  2. 3 0
      src/borg/testsuite/archiver/create_cmd.py

+ 9 - 0
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:

+ 3 - 0
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))