From 3e0113966f9ddbc4aa33e75dd75f7ecfef055690 Mon Sep 17 00:00:00 2001 From: pxin Date: Wed, 9 Dec 2020 15:25:45 +0800 Subject: [PATCH 1/3] Skip some tests in _test_all_chown_common() on VxWorks --- Lib/test/test_posix.py | 71 ++++++++++--------- .../2020-12-09-15-23-28.bpo-31904.ghj38d.rst | 1 + 2 files changed, 38 insertions(+), 34 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2020-12-09-15-23-28.bpo-31904.ghj38d.rst diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 185b293b070469..dcad4b0ba6c2d5 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -724,41 +724,44 @@ def check_stat(uid, gid): chown_func(first_param, uid, -1) check_stat(uid, gid) - if uid == 0: - # Try an amusingly large uid/gid to make sure we handle - # large unsigned values. (chown lets you use any - # uid/gid you like, even if they aren't defined.) - # - # This problem keeps coming up: - # http://bugs.python.org/issue1747858 - # http://bugs.python.org/issue4591 - # http://bugs.python.org/issue15301 - # Hopefully the fix in 4591 fixes it for good! - # - # This part of the test only runs when run as root. - # Only scary people run their tests as root. - - big_value = 2**31 - chown_func(first_param, big_value, big_value) - check_stat(big_value, big_value) - chown_func(first_param, -1, -1) - check_stat(big_value, big_value) - chown_func(first_param, uid, gid) - check_stat(uid, gid) - elif platform.system() in ('HP-UX', 'SunOS'): - # HP-UX and Solaris can allow a non-root user to chown() to root - # (issue #5113) - raise unittest.SkipTest("Skipping because of non-standard chown() " - "behavior") - else: - # non-root cannot chown to root, raises OSError - self.assertRaises(OSError, chown_func, first_param, 0, 0) - check_stat(uid, gid) - self.assertRaises(OSError, chown_func, first_param, 0, -1) - check_stat(uid, gid) - if 0 not in os.getgroups(): - self.assertRaises(OSError, chown_func, first_param, -1, 0) + # On VxWorks root user id is 1 and 0 means no login user. It also + # allows non-root user to chown() to root. + if sys.platform != "vxworks": + if uid == 0: + # Try an amusingly large uid/gid to make sure we handle + # large unsigned values. (chown lets you use any + # uid/gid you like, even if they aren't defined.) + # + # This problem keeps coming up: + # http://bugs.python.org/issue1747858 + # http://bugs.python.org/issue4591 + # http://bugs.python.org/issue15301 + # Hopefully the fix in 4591 fixes it for good! + # + # This part of the test only runs when run as root. + # Only scary people run their tests as root. + + big_value = 2**31 + chown_func(first_param, big_value, big_value) + check_stat(big_value, big_value) + chown_func(first_param, -1, -1) + check_stat(big_value, big_value) + chown_func(first_param, uid, gid) + check_stat(uid, gid) + elif platform.system() in ('HP-UX', 'SunOS'): + # HP-UX and Solaris can allow a non-root user to chown() to root + # (issue #5113) + raise unittest.SkipTest("Skipping because of non-standard chown() " + "behavior") + else: + # non-root cannot chown to root, raises OSError + self.assertRaises(OSError, chown_func, first_param, 0, 0) + check_stat(uid, gid) + self.assertRaises(OSError, chown_func, first_param, 0, -1) check_stat(uid, gid) + if 0 not in os.getgroups(): + self.assertRaises(OSError, chown_func, first_param, -1, 0) + check_stat(uid, gid) # test illegal types for t in str, float: self.assertRaises(TypeError, chown_func, first_param, t(uid), gid) diff --git a/Misc/NEWS.d/next/Tests/2020-12-09-15-23-28.bpo-31904.ghj38d.rst b/Misc/NEWS.d/next/Tests/2020-12-09-15-23-28.bpo-31904.ghj38d.rst new file mode 100644 index 00000000000000..654562bf407b16 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-12-09-15-23-28.bpo-31904.ghj38d.rst @@ -0,0 +1 @@ +Skip some tests in _test_all_chown_common() on VxWorks. From d5e2e47fc5c9578de21b032d967c49199638a6cc Mon Sep 17 00:00:00 2001 From: pxin Date: Fri, 11 Dec 2020 17:04:33 +0800 Subject: [PATCH 2/3] test chown for super user on VxWorks --- Lib/test/test_posix.py | 77 ++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index dcad4b0ba6c2d5..d9adc96b1b3719 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -724,44 +724,47 @@ def check_stat(uid, gid): chown_func(first_param, uid, -1) check_stat(uid, gid) - # On VxWorks root user id is 1 and 0 means no login user. It also - # allows non-root user to chown() to root. - if sys.platform != "vxworks": - if uid == 0: - # Try an amusingly large uid/gid to make sure we handle - # large unsigned values. (chown lets you use any - # uid/gid you like, even if they aren't defined.) - # - # This problem keeps coming up: - # http://bugs.python.org/issue1747858 - # http://bugs.python.org/issue4591 - # http://bugs.python.org/issue15301 - # Hopefully the fix in 4591 fixes it for good! - # - # This part of the test only runs when run as root. - # Only scary people run their tests as root. - - big_value = 2**31 - chown_func(first_param, big_value, big_value) - check_stat(big_value, big_value) - chown_func(first_param, -1, -1) - check_stat(big_value, big_value) - chown_func(first_param, uid, gid) - check_stat(uid, gid) - elif platform.system() in ('HP-UX', 'SunOS'): - # HP-UX and Solaris can allow a non-root user to chown() to root - # (issue #5113) - raise unittest.SkipTest("Skipping because of non-standard chown() " - "behavior") - else: - # non-root cannot chown to root, raises OSError - self.assertRaises(OSError, chown_func, first_param, 0, 0) - check_stat(uid, gid) - self.assertRaises(OSError, chown_func, first_param, 0, -1) + # On VxWorks root user id is 1 and 0 means no login user. And + # both are super users. + superuser_uids = ((0,) if sys.platform != "vxworks" else (0, 1)) + if uid in superuser_uids: + # Try an amusingly large uid/gid to make sure we handle + # large unsigned values. (chown lets you use any + # uid/gid you like, even if they aren't defined.) + # + # On VxWorks uid_t is defined as unsigned short. A big + # value greater than 65535 will result in underflow error. + # + # This problem keeps coming up: + # http://bugs.python.org/issue1747858 + # http://bugs.python.org/issue4591 + # http://bugs.python.org/issue15301 + # Hopefully the fix in 4591 fixes it for good! + # + # This part of the test only runs when run as root. + # Only scary people run their tests as root. + + big_value = (2**31 if sys.platform != "vxworks" else 2**15) + chown_func(first_param, big_value, big_value) + check_stat(big_value, big_value) + chown_func(first_param, -1, -1) + check_stat(big_value, big_value) + chown_func(first_param, uid, gid) + check_stat(uid, gid) + elif platform.system() in ('HP-UX', 'SunOS'): + # HP-UX and Solaris can allow a non-root user to chown() to root + # (issue #5113) + raise unittest.SkipTest("Skipping because of non-standard chown() " + "behavior") + else: + # non-root cannot chown to root, raises OSError + self.assertRaises(OSError, chown_func, first_param, 0, 0) + check_stat(uid, gid) + self.assertRaises(OSError, chown_func, first_param, 0, -1) + check_stat(uid, gid) + if 0 not in os.getgroups(): + self.assertRaises(OSError, chown_func, first_param, -1, 0) check_stat(uid, gid) - if 0 not in os.getgroups(): - self.assertRaises(OSError, chown_func, first_param, -1, 0) - check_stat(uid, gid) # test illegal types for t in str, float: self.assertRaises(TypeError, chown_func, first_param, t(uid), gid) From 212b673d67ba9aca1252d7bcd872097008886106 Mon Sep 17 00:00:00 2001 From: pxinwr Date: Tue, 15 Dec 2020 11:39:17 +0800 Subject: [PATCH 3/3] Update Lib/test/test_posix.py Co-authored-by: Victor Stinner --- Lib/test/test_posix.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index d9adc96b1b3719..80a1fe6c7b7680 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -724,10 +724,13 @@ def check_stat(uid, gid): chown_func(first_param, uid, -1) check_stat(uid, gid) - # On VxWorks root user id is 1 and 0 means no login user. And - # both are super users. - superuser_uids = ((0,) if sys.platform != "vxworks" else (0, 1)) - if uid in superuser_uids: + if sys.platform == "vxworks": + # On VxWorks, root user id is 1 and 0 means no login user: + # both are super users. + is_root = (uid in (0, 1)) + else: + is_root = (uid == 0) + if is_root: # Try an amusingly large uid/gid to make sure we handle # large unsigned values. (chown lets you use any # uid/gid you like, even if they aren't defined.)