Skip to content

Commit

Permalink
Merge pull request #1316 from exarkun/4049.skip-some-when-superuser
Browse files Browse the repository at this point in the history
Skip some tests when run as superuser

Fixes ticket:4049
  • Loading branch information
itamarst committed Jul 21, 2023
2 parents 4b9ebe9 + 60b361d commit a297d6b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 37 deletions.
Empty file added newsfragments/4049.minor
Empty file.
3 changes: 2 additions & 1 deletion src/allmydata/test/cli/test_grid_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ def test_sign_missing(self):
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 with all permissions")
def test_sign_bad_perms(self):
"""
Error reported if we can't create certificate file
Expand Down
25 changes: 8 additions & 17 deletions src/allmydata/test/test_client.py
Original file line number Diff line number Diff line change
@@ -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,
)
Expand Down Expand Up @@ -42,6 +32,7 @@
from twisted.python.filepath import (
FilePath,
)
from twisted.python.runtime import platform
from testtools.matchers import (
Equals,
AfterPreprocessing,
Expand Down Expand Up @@ -156,12 +147,12 @@ def write_config(s):
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 with all 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")
Expand Down
26 changes: 7 additions & 19 deletions src/allmydata/test/test_node.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -31,6 +21,7 @@
from twisted.python.filepath import (
FilePath,
)
from twisted.python.runtime import platform
from twisted.trial import unittest
from twisted.internet import defer

Expand Down Expand Up @@ -333,10 +324,8 @@ def test_config_items_missing_section(self):
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 with all permissions")
def test_private_config_unreadable(self):
"""
Asking for inaccessible private config is an error
Expand All @@ -351,10 +340,8 @@ def test_private_config_unreadable(self):
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 with all permissions")
def test_private_config_unreadable_preexisting(self):
"""
error if reading private config data fails
Expand Down Expand Up @@ -411,6 +398,7 @@ def make_newer():
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")
def test_write_config_unwritable_file(self):
"""
Existing behavior merely logs any errors upon writing
Expand Down

0 comments on commit a297d6b

Please sign in to comment.