mirror of
https://github.com/python/cpython.git
synced 2025-09-28 03:13:48 +00:00
bpo-28759: Skip some tests on PermissionError raised by Android (GH-4350)
Access to mkfifo(), mknod() and hard link creation is controled by SELinux on Android. Also remove test.support.android_not_root.
This commit is contained in:
parent
e0582a37c8
commit
92c2ca7633
7 changed files with 50 additions and 34 deletions
|
@ -20,7 +20,6 @@ import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
android_not_root = support.android_not_root
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def kill_on_error(proc):
|
def kill_on_error(proc):
|
||||||
|
@ -312,14 +311,16 @@ class SocketEINTRTest(EINTRBaseTest):
|
||||||
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=203162
|
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=203162
|
||||||
@support.requires_freebsd_version(10, 3)
|
@support.requires_freebsd_version(10, 3)
|
||||||
@unittest.skipUnless(hasattr(os, 'mkfifo'), 'needs mkfifo()')
|
@unittest.skipUnless(hasattr(os, 'mkfifo'), 'needs mkfifo()')
|
||||||
@unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
|
|
||||||
def _test_open(self, do_open_close_reader, do_open_close_writer):
|
def _test_open(self, do_open_close_reader, do_open_close_writer):
|
||||||
filename = support.TESTFN
|
filename = support.TESTFN
|
||||||
|
|
||||||
# Use a fifo: until the child opens it for reading, the parent will
|
# Use a fifo: until the child opens it for reading, the parent will
|
||||||
# block when trying to open it for writing.
|
# block when trying to open it for writing.
|
||||||
support.unlink(filename)
|
support.unlink(filename)
|
||||||
|
try:
|
||||||
os.mkfifo(filename)
|
os.mkfifo(filename)
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('os.mkfifo(): %s' % e)
|
||||||
self.addCleanup(support.unlink, filename)
|
self.addCleanup(support.unlink, filename)
|
||||||
|
|
||||||
code = '\n'.join((
|
code = '\n'.join((
|
||||||
|
|
|
@ -90,7 +90,7 @@ __all__ = [
|
||||||
"check__all__", "requires_android_level", "requires_multiprocessing_queue",
|
"check__all__", "requires_android_level", "requires_multiprocessing_queue",
|
||||||
# sys
|
# sys
|
||||||
"is_jython", "is_android", "check_impl_detail", "unix_shell",
|
"is_jython", "is_android", "check_impl_detail", "unix_shell",
|
||||||
"setswitchinterval", "android_not_root",
|
"setswitchinterval",
|
||||||
# network
|
# network
|
||||||
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
|
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
|
||||||
"bind_unix_socket",
|
"bind_unix_socket",
|
||||||
|
@ -780,7 +780,6 @@ try:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# sys.getandroidapilevel() is only available on Android
|
# sys.getandroidapilevel() is only available on Android
|
||||||
is_android = False
|
is_android = False
|
||||||
android_not_root = (is_android and os.geteuid() != 0)
|
|
||||||
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
|
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
|
||||||
|
|
|
@ -8,7 +8,6 @@ import sys
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
import warnings
|
||||||
from test import support
|
from test import support
|
||||||
android_not_root = support.android_not_root
|
|
||||||
|
|
||||||
|
|
||||||
def create_file(filename, data=b'foo'):
|
def create_file(filename, data=b'foo'):
|
||||||
|
@ -213,9 +212,11 @@ class GenericTest:
|
||||||
def test_samefile_on_symlink(self):
|
def test_samefile_on_symlink(self):
|
||||||
self._test_samefile_on_link_func(os.symlink)
|
self._test_samefile_on_link_func(os.symlink)
|
||||||
|
|
||||||
@unittest.skipIf(android_not_root, "hard links not allowed, non root user")
|
|
||||||
def test_samefile_on_link(self):
|
def test_samefile_on_link(self):
|
||||||
|
try:
|
||||||
self._test_samefile_on_link_func(os.link)
|
self._test_samefile_on_link_func(os.link)
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('os.link(): %s' % e)
|
||||||
|
|
||||||
def test_samestat(self):
|
def test_samestat(self):
|
||||||
test_fn1 = support.TESTFN
|
test_fn1 = support.TESTFN
|
||||||
|
@ -253,9 +254,11 @@ class GenericTest:
|
||||||
def test_samestat_on_symlink(self):
|
def test_samestat_on_symlink(self):
|
||||||
self._test_samestat_on_link_func(os.symlink)
|
self._test_samestat_on_link_func(os.symlink)
|
||||||
|
|
||||||
@unittest.skipIf(android_not_root, "hard links not allowed, non root user")
|
|
||||||
def test_samestat_on_link(self):
|
def test_samestat_on_link(self):
|
||||||
|
try:
|
||||||
self._test_samestat_on_link_func(os.link)
|
self._test_samestat_on_link_func(os.link)
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('os.link(): %s' % e)
|
||||||
|
|
||||||
def test_sameopenfile(self):
|
def test_sameopenfile(self):
|
||||||
filename = support.TESTFN
|
filename = support.TESTFN
|
||||||
|
|
|
@ -11,7 +11,6 @@ import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
android_not_root = support.android_not_root
|
|
||||||
TESTFN = support.TESTFN
|
TESTFN = support.TESTFN
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -1911,10 +1910,12 @@ class _BasePathTest(object):
|
||||||
self.assertFalse((P / 'fileA' / 'bah').is_fifo())
|
self.assertFalse((P / 'fileA' / 'bah').is_fifo())
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(os, "mkfifo"), "os.mkfifo() required")
|
@unittest.skipUnless(hasattr(os, "mkfifo"), "os.mkfifo() required")
|
||||||
@unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
|
|
||||||
def test_is_fifo_true(self):
|
def test_is_fifo_true(self):
|
||||||
P = self.cls(BASE, 'myfifo')
|
P = self.cls(BASE, 'myfifo')
|
||||||
|
try:
|
||||||
os.mkfifo(str(P))
|
os.mkfifo(str(P))
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('os.mkfifo(): %s' % e)
|
||||||
self.assertTrue(P.is_fifo())
|
self.assertTrue(P.is_fifo())
|
||||||
self.assertFalse(P.is_socket())
|
self.assertFalse(P.is_socket())
|
||||||
self.assertFalse(P.is_file())
|
self.assertFalse(P.is_file())
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
from test.support.script_helper import assert_python_ok
|
from test.support.script_helper import assert_python_ok
|
||||||
android_not_root = support.android_not_root
|
|
||||||
|
|
||||||
# Skip these tests if there is no posix module.
|
# Skip these tests if there is no posix module.
|
||||||
posix = support.import_module('posix')
|
posix = support.import_module('posix')
|
||||||
|
@ -504,15 +503,16 @@ class PosixTester(unittest.TestCase):
|
||||||
posix.stat, list(os.fsencode(support.TESTFN)))
|
posix.stat, list(os.fsencode(support.TESTFN)))
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(posix, 'mkfifo'), "don't have mkfifo()")
|
@unittest.skipUnless(hasattr(posix, 'mkfifo'), "don't have mkfifo()")
|
||||||
@unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
|
|
||||||
def test_mkfifo(self):
|
def test_mkfifo(self):
|
||||||
support.unlink(support.TESTFN)
|
support.unlink(support.TESTFN)
|
||||||
|
try:
|
||||||
posix.mkfifo(support.TESTFN, stat.S_IRUSR | stat.S_IWUSR)
|
posix.mkfifo(support.TESTFN, stat.S_IRUSR | stat.S_IWUSR)
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('posix.mkfifo(): %s' % e)
|
||||||
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
|
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(posix, 'mknod') and hasattr(stat, 'S_IFIFO'),
|
@unittest.skipUnless(hasattr(posix, 'mknod') and hasattr(stat, 'S_IFIFO'),
|
||||||
"don't have mknod()/S_IFIFO")
|
"don't have mknod()/S_IFIFO")
|
||||||
@unittest.skipIf(android_not_root, "mknod not allowed, non root user")
|
|
||||||
def test_mknod(self):
|
def test_mknod(self):
|
||||||
# Test using mknod() to create a FIFO (the only use specified
|
# Test using mknod() to create a FIFO (the only use specified
|
||||||
# by POSIX).
|
# by POSIX).
|
||||||
|
@ -523,7 +523,7 @@ class PosixTester(unittest.TestCase):
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
# Some old systems don't allow unprivileged users to use
|
# Some old systems don't allow unprivileged users to use
|
||||||
# mknod(), or only support creating device nodes.
|
# mknod(), or only support creating device nodes.
|
||||||
self.assertIn(e.errno, (errno.EPERM, errno.EINVAL))
|
self.assertIn(e.errno, (errno.EPERM, errno.EINVAL, errno.EACCES))
|
||||||
else:
|
else:
|
||||||
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
|
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
|
||||||
|
|
||||||
|
@ -533,7 +533,7 @@ class PosixTester(unittest.TestCase):
|
||||||
posix.mknod(path=support.TESTFN, mode=mode, device=0,
|
posix.mknod(path=support.TESTFN, mode=mode, device=0,
|
||||||
dir_fd=None)
|
dir_fd=None)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
self.assertIn(e.errno, (errno.EPERM, errno.EINVAL))
|
self.assertIn(e.errno, (errno.EPERM, errno.EINVAL, errno.EACCES))
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(posix, 'stat'), 'test needs posix.stat()')
|
@unittest.skipUnless(hasattr(posix, 'stat'), 'test needs posix.stat()')
|
||||||
@unittest.skipUnless(hasattr(posix, 'makedev'), 'test needs posix.makedev()')
|
@unittest.skipUnless(hasattr(posix, 'makedev'), 'test needs posix.makedev()')
|
||||||
|
@ -1018,11 +1018,13 @@ class PosixTester(unittest.TestCase):
|
||||||
posix.close(f)
|
posix.close(f)
|
||||||
|
|
||||||
@unittest.skipUnless(os.link in os.supports_dir_fd, "test needs dir_fd support in os.link()")
|
@unittest.skipUnless(os.link in os.supports_dir_fd, "test needs dir_fd support in os.link()")
|
||||||
@unittest.skipIf(android_not_root, "hard link not allowed, non root user")
|
|
||||||
def test_link_dir_fd(self):
|
def test_link_dir_fd(self):
|
||||||
f = posix.open(posix.getcwd(), posix.O_RDONLY)
|
f = posix.open(posix.getcwd(), posix.O_RDONLY)
|
||||||
try:
|
try:
|
||||||
posix.link(support.TESTFN, support.TESTFN + 'link', src_dir_fd=f, dst_dir_fd=f)
|
posix.link(support.TESTFN, support.TESTFN + 'link', src_dir_fd=f, dst_dir_fd=f)
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('posix.link(): %s' % e)
|
||||||
|
else:
|
||||||
# should have same inodes
|
# should have same inodes
|
||||||
self.assertEqual(posix.stat(support.TESTFN)[1],
|
self.assertEqual(posix.stat(support.TESTFN)[1],
|
||||||
posix.stat(support.TESTFN + 'link')[1])
|
posix.stat(support.TESTFN + 'link')[1])
|
||||||
|
@ -1042,7 +1044,6 @@ class PosixTester(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipUnless((os.mknod in os.supports_dir_fd) and hasattr(stat, 'S_IFIFO'),
|
@unittest.skipUnless((os.mknod in os.supports_dir_fd) and hasattr(stat, 'S_IFIFO'),
|
||||||
"test requires both stat.S_IFIFO and dir_fd support for os.mknod()")
|
"test requires both stat.S_IFIFO and dir_fd support for os.mknod()")
|
||||||
@unittest.skipIf(android_not_root, "mknod not allowed, non root user")
|
|
||||||
def test_mknod_dir_fd(self):
|
def test_mknod_dir_fd(self):
|
||||||
# Test using mknodat() to create a FIFO (the only use specified
|
# Test using mknodat() to create a FIFO (the only use specified
|
||||||
# by POSIX).
|
# by POSIX).
|
||||||
|
@ -1054,7 +1055,7 @@ class PosixTester(unittest.TestCase):
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
# Some old systems don't allow unprivileged users to use
|
# Some old systems don't allow unprivileged users to use
|
||||||
# mknod(), or only support creating device nodes.
|
# mknod(), or only support creating device nodes.
|
||||||
self.assertIn(e.errno, (errno.EPERM, errno.EINVAL))
|
self.assertIn(e.errno, (errno.EPERM, errno.EINVAL, errno.EACCES))
|
||||||
else:
|
else:
|
||||||
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
|
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
|
||||||
finally:
|
finally:
|
||||||
|
@ -1126,12 +1127,15 @@ class PosixTester(unittest.TestCase):
|
||||||
posix.close(f)
|
posix.close(f)
|
||||||
|
|
||||||
@unittest.skipUnless(os.mkfifo in os.supports_dir_fd, "test needs dir_fd support in os.mkfifo()")
|
@unittest.skipUnless(os.mkfifo in os.supports_dir_fd, "test needs dir_fd support in os.mkfifo()")
|
||||||
@unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
|
|
||||||
def test_mkfifo_dir_fd(self):
|
def test_mkfifo_dir_fd(self):
|
||||||
support.unlink(support.TESTFN)
|
support.unlink(support.TESTFN)
|
||||||
f = posix.open(posix.getcwd(), posix.O_RDONLY)
|
f = posix.open(posix.getcwd(), posix.O_RDONLY)
|
||||||
try:
|
try:
|
||||||
posix.mkfifo(support.TESTFN, stat.S_IRUSR | stat.S_IWUSR, dir_fd=f)
|
try:
|
||||||
|
posix.mkfifo(support.TESTFN,
|
||||||
|
stat.S_IRUSR | stat.S_IWUSR, dir_fd=f)
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('posix.mkfifo(): %s' % e)
|
||||||
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
|
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
|
||||||
finally:
|
finally:
|
||||||
posix.close(f)
|
posix.close(f)
|
||||||
|
|
|
@ -22,7 +22,7 @@ import tarfile
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import TESTFN, android_not_root
|
from test.support import TESTFN
|
||||||
|
|
||||||
TESTFN2 = TESTFN + "2"
|
TESTFN2 = TESTFN + "2"
|
||||||
|
|
||||||
|
@ -769,7 +769,6 @@ class TestShutil(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipIf(os.name == 'nt', 'temporarily disabled on Windows')
|
@unittest.skipIf(os.name == 'nt', 'temporarily disabled on Windows')
|
||||||
@unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
|
@unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
|
||||||
@unittest.skipIf(android_not_root, "hard links not allowed, non root user")
|
|
||||||
def test_dont_copy_file_onto_link_to_itself(self):
|
def test_dont_copy_file_onto_link_to_itself(self):
|
||||||
# bug 851123.
|
# bug 851123.
|
||||||
os.mkdir(TESTFN)
|
os.mkdir(TESTFN)
|
||||||
|
@ -778,7 +777,10 @@ class TestShutil(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
with open(src, 'w') as f:
|
with open(src, 'w') as f:
|
||||||
f.write('cheddar')
|
f.write('cheddar')
|
||||||
|
try:
|
||||||
os.link(src, dst)
|
os.link(src, dst)
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('os.link(): %s' % e)
|
||||||
self.assertRaises(shutil.SameFileError, shutil.copyfile, src, dst)
|
self.assertRaises(shutil.SameFileError, shutil.copyfile, src, dst)
|
||||||
with open(src, 'r') as f:
|
with open(src, 'r') as f:
|
||||||
self.assertEqual(f.read(), 'cheddar')
|
self.assertEqual(f.read(), 'cheddar')
|
||||||
|
@ -822,9 +824,11 @@ class TestShutil(unittest.TestCase):
|
||||||
|
|
||||||
# Issue #3002: copyfile and copytree block indefinitely on named pipes
|
# Issue #3002: copyfile and copytree block indefinitely on named pipes
|
||||||
@unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
|
@unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
|
||||||
@unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
|
|
||||||
def test_copyfile_named_pipe(self):
|
def test_copyfile_named_pipe(self):
|
||||||
|
try:
|
||||||
os.mkfifo(TESTFN)
|
os.mkfifo(TESTFN)
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('os.mkfifo(): %s' % e)
|
||||||
try:
|
try:
|
||||||
self.assertRaises(shutil.SpecialFileError,
|
self.assertRaises(shutil.SpecialFileError,
|
||||||
shutil.copyfile, TESTFN, TESTFN2)
|
shutil.copyfile, TESTFN, TESTFN2)
|
||||||
|
@ -833,7 +837,6 @@ class TestShutil(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
os.remove(TESTFN)
|
os.remove(TESTFN)
|
||||||
|
|
||||||
@unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
|
|
||||||
@unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
|
@unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
|
||||||
@support.skip_unless_symlink
|
@support.skip_unless_symlink
|
||||||
def test_copytree_named_pipe(self):
|
def test_copytree_named_pipe(self):
|
||||||
|
@ -842,7 +845,10 @@ class TestShutil(unittest.TestCase):
|
||||||
subdir = os.path.join(TESTFN, "subdir")
|
subdir = os.path.join(TESTFN, "subdir")
|
||||||
os.mkdir(subdir)
|
os.mkdir(subdir)
|
||||||
pipe = os.path.join(subdir, "mypipe")
|
pipe = os.path.join(subdir, "mypipe")
|
||||||
|
try:
|
||||||
os.mkfifo(pipe)
|
os.mkfifo(pipe)
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('os.mkfifo(): %s' % e)
|
||||||
try:
|
try:
|
||||||
shutil.copytree(TESTFN, TESTFN2)
|
shutil.copytree(TESTFN, TESTFN2)
|
||||||
except shutil.Error as e:
|
except shutil.Error as e:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from test.support import TESTFN, import_fresh_module, android_not_root
|
from test.support import TESTFN, import_fresh_module
|
||||||
|
|
||||||
c_stat = import_fresh_module('stat', fresh=['_stat'])
|
c_stat = import_fresh_module('stat', fresh=['_stat'])
|
||||||
py_stat = import_fresh_module('stat', blocked=['_stat'])
|
py_stat = import_fresh_module('stat', blocked=['_stat'])
|
||||||
|
@ -168,9 +168,11 @@ class TestFilemode:
|
||||||
self.assertS_IS("LNK", st_mode)
|
self.assertS_IS("LNK", st_mode)
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(os, 'mkfifo'), 'os.mkfifo not available')
|
@unittest.skipUnless(hasattr(os, 'mkfifo'), 'os.mkfifo not available')
|
||||||
@unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
|
|
||||||
def test_fifo(self):
|
def test_fifo(self):
|
||||||
|
try:
|
||||||
os.mkfifo(TESTFN, 0o700)
|
os.mkfifo(TESTFN, 0o700)
|
||||||
|
except PermissionError as e:
|
||||||
|
self.skipTest('os.mkfifo(): %s' % e)
|
||||||
st_mode, modestr = self.get_mode()
|
st_mode, modestr = self.get_mode()
|
||||||
self.assertEqual(modestr, 'prwx------')
|
self.assertEqual(modestr, 'prwx------')
|
||||||
self.assertS_IS("FIFO", st_mode)
|
self.assertS_IS("FIFO", st_mode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue