skip permission-related tests if the environment is not suitable

posix superuser can do anything on the filesystem
This commit is contained in:
Jean-Paul Calderone 2023-07-20 11:36:30 -04:00
parent 9585925627
commit 2091b7ee86
3 changed files with 17 additions and 37 deletions

View File

@ -222,7 +222,8 @@ class GridManagerCommandLine(TestCase):
result.output,
)
@skipIf(not platform.isLinux(), "I only know how permissions work on linux")
@skipIf(platform.isWindows(), "We don't know how to set permissions on Windows.")
@skipIf(os.getuid() == 0, "cannot test as superuser which all of the permissions")
def test_sign_bad_perms(self):
"""
Error reported if we can't create certificate file

View File

@ -1,17 +1,7 @@
"""
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
from __future__ import annotations
import os
import sys
from unittest import skipIf
from functools import (
partial,
)
@ -42,6 +32,7 @@ from twisted.internet import defer
from twisted.python.filepath import (
FilePath,
)
from twisted.python.runtime import platform
from testtools.matchers import (
Equals,
AfterPreprocessing,
@ -156,12 +147,12 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
yield client.create_client(basedir)
self.assertIn("[client]helper.furl", str(ctx.exception))
# if somebody knows a clever way to do this (cause
# EnvironmentError when reading a file that really exists), on
# windows, please fix this
@skipIf(platform.isWindows(), "We don't know how to set permissions on Windows.")
@skipIf(os.getuid() == 0, "cannot test as superuser which all of the permissions")
def test_unreadable_config(self):
if sys.platform == "win32":
# if somebody knows a clever way to do this (cause
# EnvironmentError when reading a file that really exists), on
# windows, please fix this
raise unittest.SkipTest("can't make unreadable files on windows")
basedir = "test_client.Basic.test_unreadable_config"
os.mkdir(basedir)
fn = os.path.join(basedir, "tahoe.cfg")

View File

@ -1,14 +1,4 @@
"""
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
from __future__ import annotations
import base64
import os
@ -31,6 +21,7 @@ from unittest import skipIf
from twisted.python.filepath import (
FilePath,
)
from twisted.python.runtime import platform
from twisted.trial import unittest
from twisted.internet import defer
@ -333,10 +324,8 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
default = [("hello", "world")]
self.assertEqual(config.items("nosuch", default), default)
@skipIf(
"win32" in sys.platform.lower() or "cygwin" in sys.platform.lower(),
"We don't know how to set permissions on Windows.",
)
@skipIf(platform.isWindows(), "We don't know how to set permissions on Windows.")
@skipIf(os.getuid() == 0, "cannot test as superuser which all of the permissions")
def test_private_config_unreadable(self):
"""
Asking for inaccessible private config is an error
@ -351,10 +340,8 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
with self.assertRaises(Exception):
config.get_or_create_private_config("foo")
@skipIf(
"win32" in sys.platform.lower() or "cygwin" in sys.platform.lower(),
"We don't know how to set permissions on Windows.",
)
@skipIf(platform.isWindows(), "We don't know how to set permissions on Windows.")
@skipIf(os.getuid() == 0, "cannot test as superuser which all of the permissions")
def test_private_config_unreadable_preexisting(self):
"""
error if reading private config data fails
@ -411,6 +398,7 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
self.assertEqual(len(counter), 1) # don't call unless necessary
self.assertEqual(value, "newer")
@skipIf(os.getuid() == 0, "cannot test as superuser which all of the permissions")
def test_write_config_unwritable_file(self):
"""
Existing behavior merely logs any errors upon writing