bpo-36234: Add more tests to PosixUidGidTests (GH-12234)
test_posix.PosixUidGidTests: * Add tests for invalid uid/gid type (str) * Add UID_OVERFLOW and GID_OVERFLOW constants to replace (1 << 32) Initial patch written by David Malcolm. Co-Authored-By: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
parent
cc353a0cd9
commit
876e82b4f3
|
@ -1796,36 +1796,46 @@ class LinkTests(unittest.TestCase):
|
|||
|
||||
@unittest.skipIf(sys.platform == "win32", "Posix specific tests")
|
||||
class PosixUidGidTests(unittest.TestCase):
|
||||
# uid_t and gid_t are 32-bit unsigned integers on Linux
|
||||
UID_OVERFLOW = (1 << 32)
|
||||
GID_OVERFLOW = (1 << 32)
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'setuid'), 'test needs os.setuid()')
|
||||
def test_setuid(self):
|
||||
if os.getuid() != 0:
|
||||
self.assertRaises(OSError, os.setuid, 0)
|
||||
self.assertRaises(OverflowError, os.setuid, 1<<32)
|
||||
self.assertRaises(TypeError, os.setuid, 'not an int')
|
||||
self.assertRaises(OverflowError, os.setuid, self.UID_OVERFLOW)
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'setgid'), 'test needs os.setgid()')
|
||||
def test_setgid(self):
|
||||
if os.getuid() != 0 and not HAVE_WHEEL_GROUP:
|
||||
self.assertRaises(OSError, os.setgid, 0)
|
||||
self.assertRaises(OverflowError, os.setgid, 1<<32)
|
||||
self.assertRaises(TypeError, os.setgid, 'not an int')
|
||||
self.assertRaises(OverflowError, os.setgid, self.GID_OVERFLOW)
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'seteuid'), 'test needs os.seteuid()')
|
||||
def test_seteuid(self):
|
||||
if os.getuid() != 0:
|
||||
self.assertRaises(OSError, os.seteuid, 0)
|
||||
self.assertRaises(OverflowError, os.seteuid, 1<<32)
|
||||
self.assertRaises(TypeError, os.setegid, 'not an int')
|
||||
self.assertRaises(OverflowError, os.seteuid, self.UID_OVERFLOW)
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'setegid'), 'test needs os.setegid()')
|
||||
def test_setegid(self):
|
||||
if os.getuid() != 0 and not HAVE_WHEEL_GROUP:
|
||||
self.assertRaises(OSError, os.setegid, 0)
|
||||
self.assertRaises(OverflowError, os.setegid, 1<<32)
|
||||
self.assertRaises(TypeError, os.setegid, 'not an int')
|
||||
self.assertRaises(OverflowError, os.setegid, self.GID_OVERFLOW)
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'setreuid'), 'test needs os.setreuid()')
|
||||
def test_setreuid(self):
|
||||
if os.getuid() != 0:
|
||||
self.assertRaises(OSError, os.setreuid, 0, 0)
|
||||
self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
|
||||
self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
|
||||
self.assertRaises(TypeError, os.setreuid, 'not an int', 0)
|
||||
self.assertRaises(TypeError, os.setreuid, 0, 'not an int')
|
||||
self.assertRaises(OverflowError, os.setreuid, self.UID_OVERFLOW, 0)
|
||||
self.assertRaises(OverflowError, os.setreuid, 0, self.UID_OVERFLOW)
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'setreuid'), 'test needs os.setreuid()')
|
||||
def test_setreuid_neg1(self):
|
||||
|
@ -1839,8 +1849,10 @@ class PosixUidGidTests(unittest.TestCase):
|
|||
def test_setregid(self):
|
||||
if os.getuid() != 0 and not HAVE_WHEEL_GROUP:
|
||||
self.assertRaises(OSError, os.setregid, 0, 0)
|
||||
self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
|
||||
self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
|
||||
self.assertRaises(TypeError, os.setregid, 'not an int', 0)
|
||||
self.assertRaises(TypeError, os.setregid, 0, 'not an int')
|
||||
self.assertRaises(OverflowError, os.setregid, self.GID_OVERFLOW, 0)
|
||||
self.assertRaises(OverflowError, os.setregid, 0, self.GID_OVERFLOW)
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()')
|
||||
def test_setregid_neg1(self):
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
test_posix.PosixUidGidTests: add tests for invalid uid/gid type (str).
|
||||
Initial patch written by David Malcolm.
|
Loading…
Reference in New Issue