summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_posix.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_posix.py')
-rw-r--r--Lib/test/test_posix.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 1fb3c48..179864a 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -9,6 +9,7 @@ except ImportError:
import time
import os
+import pwd
import unittest
import warnings
warnings.filterwarnings('ignore', '.* potential security risk .*',
@@ -141,6 +142,33 @@ class PosixTester(unittest.TestCase):
if hasattr(posix, 'stat'):
self.assert_(posix.stat(test_support.TESTFN))
+ if hasattr(posix, 'chown'):
+ def test_chown(self):
+ # raise an OSError if the file does not exist
+ os.unlink(test_support.TESTFN)
+ self.assertRaises(OSError, posix.chown, test_support.TESTFN, -1, -1)
+
+ # re-create the file
+ open(test_support.TESTFN, 'w').close()
+ if os.getuid() == 0:
+ try:
+ # Many linux distros have a nfsnobody user as MAX_UID-2
+ # that makes a good test case for signedness issues.
+ # http://bugs.python.org/issue1747858
+ # This part of the test only runs when run as root.
+ # Only scary people run their tests as root.
+ ent = pwd.getpwnam('nfsnobody')
+ posix.chown(test_support.TESTFN, ent.pw_uid, ent.pw_gid)
+ except KeyError:
+ pass
+ else:
+ # non-root cannot chown to root, raises OSError
+ self.assertRaises(OSError, posix.chown,
+ test_support.TESTFN, 0, 0)
+
+ # test a successful chown call
+ posix.chown(test_support.TESTFN, os.getuid(), os.getgid())
+
def test_chdir(self):
if hasattr(posix, 'chdir'):
posix.chdir(os.curdir)