8000 Android: Update tests for newly-available functions affected by SELin… · python/cpython@c51b560 · GitHub
[go: up one dir, main page]

Skip to content

Commit c51b560

Browse files
authored
Android: Update tests for newly-available functions affected by SELinux (#126015)
Skip tests on Android that involve use of SELinux-protected methods.
1 parent 44becb8 commit c51b560

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

Lib/test/support/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
520520

521521
is_android = sys.platform == "android"
522522

523+
def skip_android_selinux(name):
524+
return unittest.skipIf(
525+
sys.platform == "android", f"Android blocks {name} with SELinux"
526+
)
527+
523528
if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos"}:
524529
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
525530
else:

Lib/test/test_socket.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,7 @@ def test_sethostname(self):
11111111

11121112
@unittest.skipUnless(hasattr(socket, 'if_nameindex'),
11131113
'socket.if_nameindex() not available.')
1114+
@support.skip_android_selinux('if_nameindex')
11141115
def testInterfaceNameIndex(self):
11151116
interfaces = socket.if_nameindex()
11161117
for index, name in interfaces:
@@ -1127,6 +1128,7 @@ def testInterfaceNameIndex(self):
11271128

11281129
@unittest.skipUnless(hasattr(socket, 'if_indextoname'),
11291130
'socket.if_indextoname() not available.')
1131+
@support.skip_android_selinux('if_indextoname')
11301132
def testInvalidInterfaceIndexToName(self):
11311133
self.assertRaises(OSError, socket.if_indextoname, 0)
11321134
self.assertRaises(OverflowError, socket.if_indextoname, -1)
@@ -1146,6 +1148,7 @@ def testInvalidInterfaceIndexToName(self):
11461148

11471149
@unittest.skipUnless(hasattr(socket, 'if_nametoindex'),
11481150
'socket.if_nametoindex() not available.')
1151+
@support.skip_android_selinux('if_nametoindex')
11491152
def testInvalidInterfaceNameToIndex(self):
11501153
self.assertRaises(TypeError, socket.if_nametoindex, 0)
11511154
self.assertRaises(OSError, socket.if_nametoindex, '_DEADBEEF')
@@ -1878,6 +1881,7 @@ def test_getfqdn_filter_localhost(self):
18781881
@unittest.skipIf(sys.platform == 'win32', 'does not work on Windows')
18791882
@unittest.skipIf(AIX, 'Symbolic scope id does not work')
18801883
@unittest.skipUnless(hasattr(socket, 'if_nameindex'), "test needs socket.if_nameindex()")
1884+
@support.skip_android_selinux('if_nameindex')
18811885
def test_getaddrinfo_ipv6_scopeid_symbolic(self):
18821886
# Just pick up any network interface (Linux, Mac OS X)
18831887
(ifindex, test_interface) = socket.if_nameindex()[0]
@@ -1911,6 +1915,7 @@ def test_getaddrinfo_ipv6_scopeid_numeric(self):
19111915
@unittest.skipIf(sys.platform == 'win32', 'does not work on Windows')
19121916
@unittest.skipIf(AIX, 'Symbolic scope id does not work')
19131917
@unittest.skipUnless(hasattr(socket, 'if_nameindex'), "test needs socket.if_nameindex()")
1918+
@support.skip_android_selinux('if_nameindex')
19141919
def test_getnameinfo_ipv6_scopeid_symbolic(self):
19151920
# Just pick up any network interface.
19161921
(ifindex, test_interface) = socket.if_nameindex()[0]

Lib/test/test_termios.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import tempfile
55
import unittest
6+
from test import support
67
from test.support.import_helper import import_module
78

89
termios = import_module('termios')
@@ -18,10 +19,16 @@ def setUp(self):
1819
tmp = self.enterContext(tempfile.TemporaryFile(mode='wb', buffering=0))
1920
self.bad_fd = tmp.fileno()
2021

21-
def assertRaisesTermiosError(self, errno, callable, *args):
22+
def assertRaisesTermiosError(self, err, callable, *args):
23+
# Some versions of Android return EACCES when calling termios functions
24+
# on a regular file.
25+
errs = [err]
26+
if sys.platform == 'android' and err == errno.ENOTTY:
27+
errs.append(errno.EACCES)
28+
2229
with self.assertRaises(termios.error) as cm:
2330
callable(*args)
24-
self.assertEqual(cm.exception.args[0], errno)
31+
self.assertIn(cm.exception.args[0], errs)
2532

2633
def test_tcgetattr(self):
2734
attrs = termios.tcgetattr(self.fd)
@@ -90,6 +97,7 @@ def test_tcsetattr_errors(self):
9097
self.assertRaises(TypeError, termios.tcsetattr, object(), termios.TCSANOW, attrs)
9198
self.assertRaises(TypeError, termios.tcsetattr, self.fd, termios.TCSANOW)
9299

100+
@support.skip_android_selinux('tcsendbreak')
93101
def test_tcsendbreak(self):
94102
try:
95103
termios.tcsendbreak(self.fd, 1)
@@ -100,6 +108,7 @@ def test_tcsendbreak(self):
100108
raise
101109
termios.tcsendbreak(self.stream, 1)
102110

111+
@support.skip_android_selinux('tcsendbreak')
103112
def test_tcsendbreak_errors(self):
104113
self.assertRaises(OverflowError, termios.tcsendbreak, self.fd, 2**1000)
105114
self.assertRaises(TypeError, termios.tcsendbreak, self.fd, 0.0)
@@ -110,10 +119,12 @@ def test_tcsendbreak_errors(self):
110119
self.assertRaises(TypeError, termios.tcsendbreak, object(), 0)
111120
self.assertRaises(TypeError, termios.tcsendbreak, self.fd)
112121

122+
@support.skip_android_selinux('tcdrain')
113123
def test_tcdrain(self):
114124
termios.tcdrain(self.fd)
115125
termios.tcdrain(self.stream)
116126

127+
@support.skip_android_selinux('tcdrain')
117128
def test_tcdrain_errors(self):
118129
self.assertRaisesTermiosError(errno.ENOTTY, termios.tcdrain, self.bad_fd)
119130
self.assertRaises(ValueError, termios.tcdrain, -1)
@@ -136,12 +147,14 @@ def test_tcflush_errors(self):
136147
self.assertRaises(TypeError, termios.tcflush, object(), termios.TCIFLUSH)
137148
self.assertRaises(TypeError, termios.tcflush, self.fd)
138149

150+
@support.skip_android_selinux('tcflow')
139151
def test_tcflow(self):
140152
termios.tcflow(self.fd, termios.TCOOFF)
141153
termios.tcflow(self.fd, termios.TCOON)
142154
termios.tcflow(self.fd, termios.TCIOFF)
143155
termios.tcflow(self.fd, termios.TCION)
144156

157+
@support.skip_android_selinux('tcflow')
145158
def test_tcflow_errors(self):
146159
self.assertRaisesTermiosError(errno.EINVAL, termios.tcflow, self.fd, -1)
147160
self.assertRaises(OverflowError, termios.tcflow, self.fd, 2**1000)

0 commit comments

Comments
 (0)
0