summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-12 07:27:53 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-12 07:27:53 (GMT)
commitda5c2a064699c657b69e11aaab0eca8d743dd7ed (patch)
tree03091e586fad8bdfeb0fd966379e9bb7d30416b0 /Lib
parent083c0aac32b5edaf84f2a37232238d80ddfc00e7 (diff)
downloadcpython-da5c2a064699c657b69e11aaab0eca8d743dd7ed.zip
cpython-da5c2a064699c657b69e11aaab0eca8d743dd7ed.tar.gz
cpython-da5c2a064699c657b69e11aaab0eca8d743dd7ed.tar.bz2
Issue #4591: Uid and gid values larger than 2**31 are supported now.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_posix.py29
-rw-r--r--Lib/test/test_pwd.py9
2 files changed, 32 insertions, 6 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 2fba330..f995a9c 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -222,10 +222,20 @@ class PosixTester(unittest.TestCase):
if hasattr(posix, 'stat'):
self.assertTrue(posix.stat(test_support.TESTFN))
- def _test_all_chown_common(self, chown_func, first_param):
+ def _test_all_chown_common(self, chown_func, first_param, stat_func):
"""Common code for chown, fchown and lchown tests."""
+ def check_stat():
+ if stat_func is not None:
+ stat = stat_func(first_param)
+ self.assertEqual(stat.st_uid, os.getuid())
+ self.assertEqual(stat.st_gid, os.getgid())
# test a successful chown call
chown_func(first_param, os.getuid(), os.getgid())
+ check_stat()
+ chown_func(first_param, -1, os.getgid())
+ check_stat()
+ chown_func(first_param, os.getuid(), -1)
+ check_stat()
if os.getuid() == 0:
try:
@@ -245,8 +255,12 @@ class PosixTester(unittest.TestCase):
"behavior")
else:
# non-root cannot chown to root, raises OSError
- self.assertRaises(OSError, chown_func,
- first_param, 0, 0)
+ self.assertRaises(OSError, chown_func, first_param, 0, 0)
+ check_stat()
+ self.assertRaises(OSError, chown_func, first_param, -1, 0)
+ check_stat()
+ self.assertRaises(OSError, chown_func, first_param, 0, -1)
+ check_stat()
@unittest.skipUnless(hasattr(posix, 'chown'), "test needs os.chown()")
def test_chown(self):
@@ -256,7 +270,8 @@ class PosixTester(unittest.TestCase):
# re-create the file
open(test_support.TESTFN, 'w').close()
- self._test_all_chown_common(posix.chown, test_support.TESTFN)
+ self._test_all_chown_common(posix.chown, test_support.TESTFN,
+ getattr(posix, 'stat', None))
@unittest.skipUnless(hasattr(posix, 'fchown'), "test needs os.fchown()")
def test_fchown(self):
@@ -266,7 +281,8 @@ class PosixTester(unittest.TestCase):
test_file = open(test_support.TESTFN, 'w')
try:
fd = test_file.fileno()
- self._test_all_chown_common(posix.fchown, fd)
+ self._test_all_chown_common(posix.fchown, fd,
+ getattr(posix, 'fstat', None))
finally:
test_file.close()
@@ -275,7 +291,8 @@ class PosixTester(unittest.TestCase):
os.unlink(test_support.TESTFN)
# create a symlink
os.symlink(_DUMMY_SYMLINK, test_support.TESTFN)
- self._test_all_chown_common(posix.lchown, test_support.TESTFN)
+ self._test_all_chown_common(posix.lchown, test_support.TESTFN,
+ getattr(posix, 'lstat', None))
def test_chdir(self):
if hasattr(posix, 'chdir'):
diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py
index 67e11b6..ce8b8b3 100644
--- a/Lib/test/test_pwd.py
+++ b/Lib/test/test_pwd.py
@@ -49,7 +49,9 @@ class PwdTest(unittest.TestCase):
def test_errors(self):
self.assertRaises(TypeError, pwd.getpwuid)
+ self.assertRaises(TypeError, pwd.getpwuid, 3.14)
self.assertRaises(TypeError, pwd.getpwnam)
+ self.assertRaises(TypeError, pwd.getpwnam, 42)
self.assertRaises(TypeError, pwd.getpwall, 42)
# try to get some errors
@@ -93,6 +95,13 @@ class PwdTest(unittest.TestCase):
self.assertNotIn(fakeuid, byuids)
self.assertRaises(KeyError, pwd.getpwuid, fakeuid)
+ # -1 shouldn't be a valid uid because it has a special meaning in many
+ # uid-related functions
+ self.assertRaises(KeyError, pwd.getpwuid, -1)
+ # should be out of uid_t range
+ self.assertRaises(KeyError, pwd.getpwuid, 2**128)
+ self.assertRaises(KeyError, pwd.getpwuid, -2**128)
+
def test_main():
test_support.run_unittest(PwdTest)