avoid trying to call os.getuid on windows

This commit is contained in:
Jean-Paul Calderone 2023-08-07 12:59:44 -04:00
parent 3c8a11d468
commit b440065952
4 changed files with 14 additions and 6 deletions

View File

@ -23,6 +23,9 @@ import click.testing
from ..common_util import (
run_cli,
)
from ..common import (
superuser,
)
from twisted.internet.defer import (
inlineCallbacks,
)
@ -34,7 +37,6 @@ from twisted.python.runtime import (
)
from allmydata.util import jsonbytes as json
class GridManagerCommandLine(TestCase):
"""
Test the mechanics of the `grid-manager` command
@ -223,7 +225,7 @@ class GridManagerCommandLine(TestCase):
)
@skipIf(platform.isWindows(), "We don't know how to set permissions on Windows.")
@skipIf(os.getuid() == 0, "cannot test as superuser with all permissions")
@skipIf(superuser, "cannot test as superuser with all permissions")
def test_sign_bad_perms(self):
"""
Error reported if we can't create certificate file

View File

@ -117,6 +117,10 @@ from subprocess import (
PIPE,
)
# Is the process running as an OS user with elevated privileges (ie, root)?
# We only know how to determine this for POSIX systems.
superuser = getattr(os, "getuid", lambda: -1)() == 0
EMPTY_CLIENT_CONFIG = config_from_string(
"/dev/null",
"tub.port",

View File

@ -77,6 +77,7 @@ from allmydata.scripts.common import (
from foolscap.api import flushEventualQueue
import allmydata.test.common_util as testutil
from .common import (
superuser,
EMPTY_CLIENT_CONFIG,
SyncTestCase,
AsyncBrokenTestCase,
@ -151,7 +152,7 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
# 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 with all permissions")
@skipIf(superuser, "cannot test as superuser with all permissions")
def test_unreadable_config(self):
basedir = "test_client.Basic.test_unreadable_config"
os.mkdir(basedir)

View File

@ -62,6 +62,7 @@ from .common import (
ConstantAddresses,
SameProcessStreamEndpointAssigner,
UseNode,
superuser,
)
def port_numbers():
@ -325,7 +326,7 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
self.assertEqual(config.items("nosuch", default), default)
@skipIf(platform.isWindows(), "We don't know how to set permissions on Windows.")
@skipIf(os.getuid() == 0, "cannot test as superuser with all permissions")
@skipIf(superuser, "cannot test as superuser with all permissions")
def test_private_config_unreadable(self):
"""
Asking for inaccessible private config is an error
@ -341,7 +342,7 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
config.get_or_create_private_config("foo")
@skipIf(platform.isWindows(), "We don't know how to set permissions on Windows.")
@skipIf(os.getuid() == 0, "cannot test as superuser with all permissions")
@skipIf(superuser, "cannot test as superuser with all permissions")
def test_private_config_unreadable_preexisting(self):
"""
error if reading private config data fails
@ -398,7 +399,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 with all permissions")
@skipIf(superuser, "cannot test as superuser with all permissions")
def test_write_config_unwritable_file(self):
"""
Existing behavior merely logs any errors upon writing