From 4dba00e9ecd7fdd8f7bda34c1a369b687db1cf5a Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 16 Mar 2020 13:03:00 -0700 Subject: [PATCH 1/5] bpo-26067: Do not fail test_shutil.chown when gid/uid cannot be resolved There is no guarantee that the users primary uid or gid can be resolved in the unix group/account databases. Skip the last part of the chown test if we cannot resolve the gid or uid to a name. --- Lib/test/test_shutil.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 076c450e09bf69..d006404a17d0da 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1666,12 +1666,18 @@ def check_chown(path, uid=None, gid=None): shutil.chown(dirname, group=gid) check_chown(dirname, gid=gid) - user = pwd.getpwuid(uid)[0] - group = grp.getgrgid(gid)[0] - shutil.chown(filename, user, group) - check_chown(filename, uid, gid) - shutil.chown(dirname, user, group) - check_chown(dirname, uid, gid) + try: + user = pwd.getpwuid(uid)[0] + group = grp.getgrgid(gid)[0] + except KeyError: + # In case the uid/gid cannot be resolved. + user = None + group = None + if user is not None and group is not None: + shutil.chown(filename, user, group) + check_chown(filename, uid, gid) + shutil.chown(dirname, user, group) + check_chown(dirname, uid, gid) class TestWhich(BaseTest, unittest.TestCase): From 4649de42cdd3792d309f5fe5aea43ada5cbb1fcd Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 16 Mar 2020 20:54:56 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Misc/NEWS.d/next/Tests/2020-03-16-20-54-55.bpo-26067.m18_VV.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2020-03-16-20-54-55.bpo-26067.m18_VV.rst diff --git a/Misc/NEWS.d/next/Tests/2020-03-16-20-54-55.bpo-26067.m18_VV.rst b/Misc/NEWS.d/next/Tests/2020-03-16-20-54-55.bpo-26067.m18_VV.rst new file mode 100644 index 00000000000000..fbe8d83c6c70bc --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-03-16-20-54-55.bpo-26067.m18_VV.rst @@ -0,0 +1 @@ +- Do not fail test_shutil test_chown test when uid or gid of user cannot be resolved to a name. \ No newline at end of file From ab60c5354d7720ce3189b8fe50cbb25dbe672215 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 16 Mar 2020 14:18:23 -0700 Subject: [PATCH 3/5] Address review feedback --- Lib/test/test_shutil.py | 8 +++----- .../next/Tests/2020-03-16-20-54-55.bpo-26067.m18_VV.rst | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index d006404a17d0da..de42ba51bb4601 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1669,15 +1669,13 @@ def check_chown(path, uid=None, gid=None): try: user = pwd.getpwuid(uid)[0] group = grp.getgrgid(gid)[0] - except KeyError: - # In case the uid/gid cannot be resolved. - user = None - group = None - if user is not None and group is not None: shutil.chown(filename, user, group) check_chown(filename, uid, gid) shutil.chown(dirname, user, group) check_chown(dirname, uid, gid) + except KeyError: + # On some systems uid/gid cannot be resolved. + pass class TestWhich(BaseTest, unittest.TestCase): diff --git a/Misc/NEWS.d/next/Tests/2020-03-16-20-54-55.bpo-26067.m18_VV.rst b/Misc/NEWS.d/next/Tests/2020-03-16-20-54-55.bpo-26067.m18_VV.rst index fbe8d83c6c70bc..8b897a825d6a81 100644 --- a/Misc/NEWS.d/next/Tests/2020-03-16-20-54-55.bpo-26067.m18_VV.rst +++ b/Misc/NEWS.d/next/Tests/2020-03-16-20-54-55.bpo-26067.m18_VV.rst @@ -1 +1 @@ -- Do not fail test_shutil test_chown test when uid or gid of user cannot be resolved to a name. \ No newline at end of file +Do not fail test_shutil test_chown test when uid or gid of user cannot be resolved to a name. From 6b2d95e1dab900aab27e223b6919a929afdd1038 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 16 Mar 2020 14:20:44 -0700 Subject: [PATCH 4/5] address review feedback correctly --- Lib/test/test_shutil.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index de42ba51bb4601..9e34fb3f7924fc 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1669,13 +1669,14 @@ def check_chown(path, uid=None, gid=None): try: user = pwd.getpwuid(uid)[0] group = grp.getgrgid(gid)[0] + except KeyError: + # On some systems uid/gid cannot be resolved. + pass + else: shutil.chown(filename, user, group) check_chown(filename, uid, gid) shutil.chown(dirname, user, group) check_chown(dirname, uid, gid) - except KeyError: - # On some systems uid/gid cannot be resolved. - pass class TestWhich(BaseTest, unittest.TestCase): From ba166673b51d17421f1f44f682cc1bfefdb4fba7 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 16 Mar 2020 14:30:04 -0700 Subject: [PATCH 5/5] fix typo --- Lib/test/test_shutil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 9e34fb3f7924fc..b9fdfd1350a096 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1669,7 +1669,7 @@ def check_chown(path, uid=None, gid=None): try: user = pwd.getpwuid(uid)[0] group = grp.getgrgid(gid)[0] - except KeyError: + except KeyError: # On some systems uid/gid cannot be resolved. pass else: