Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab2d58e

Browse files
author
Charles-François Natali
committed
Issue #5113: Fix a test_posix failure on HP-UX, where non-root users can
chown() to root under certain circumstances.
1 parent 62930e1 commit ab2d58e

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Lib/test/test_posix.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
import time
1111
import os
12+
import platform
1213
import pwd
1314
import shutil
1415
import stat
@@ -229,6 +230,9 @@ def test_mknod(self):
229230

230231
def _test_all_chown_common(self, chown_func, first_param):
231232
"""Common code for chown, fchown and lchown tests."""
233+
# test a successful chown call
234+
chown_func(first_param, os.getuid(), os.getgid())
235+
232236
if os.getuid() == 0:
233237
try:
234238
# Many linux distros have a nfsnobody user as MAX_UID-2
@@ -240,12 +244,15 @@ def _test_all_chown_common(self, chown_func, first_param):
240244
chown_func(first_param, ent.pw_uid, ent.pw_gid)
241245
except KeyError:
242246
pass
247+
elif platform.system() in ('HP-UX', 'SunOS'):
248+
# HP-UX and Solaris can allow a non-root user to chown() to root
249+
# (issue #5113)
250+
raise unittest.SkipTest("Skipping because of non-standard chown() "
251+
"behavior")
243252
else:
244253
# non-root cannot chown to root, raises OSError
245254
self.assertRaises(OSError, chown_func,
246255
first_param, 0, 0)
247-
# test a successful chown call
248-
chown_func(first_param, os.getuid(), os.getgid())
249256

250257
@unittest.skipUnless(hasattr(posix, 'chown'), "test needs os.chown()")
251258
def test_chown(self):

0 commit comments

Comments
 (0)