summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-03-07 18:11:24 (GMT)
committerGitHub <noreply@github.com>2020-03-07 18:11:24 (GMT)
commit928b4dd0edf0022190a8a296c8ea65e7ef55c694 (patch)
tree3da9f52799baebf08d3bc7589f679650b3b3f776 /Lib/test
parent92b72788ecf2ee5dfac780c7dfb5ee5350fc641d (diff)
downloadcpython-928b4dd0edf0022190a8a296c8ea65e7ef55c694.zip
cpython-928b4dd0edf0022190a8a296c8ea65e7ef55c694.tar.gz
cpython-928b4dd0edf0022190a8a296c8ea65e7ef55c694.tar.bz2
bpo-38894: Fix pathlib.Path.glob in the presence of symlinks and insufficient permissions (GH-18815)
Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net> (cherry picked from commit eb7560a73d46800e4ade4a8869139b48e6c92811) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_pathlib.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index 97fc5d8..3622694 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1508,6 +1508,42 @@ class _BasePathTest(object):
self.assertEqual(set(p.glob("dirA/../file*")), { P(BASE, "dirA/../fileA") })
self.assertEqual(set(p.glob("../xyzzy")), set())
+ @support.skip_unless_symlink
+ def test_glob_permissions(self):
+ # See bpo-38894
+ P = self.cls
+ base = P(BASE) / 'permissions'
+ base.mkdir()
+
+ file1 = base / "file1"
+ file1.touch()
+ file2 = base / "file2"
+ file2.touch()
+
+ subdir = base / "subdir"
+
+ file3 = base / "file3"
+ file3.symlink_to(subdir / "other")
+
+ # Patching is needed to avoid relying on the filesystem
+ # to return the order of the files as the error will not
+ # happen if the symlink is the last item.
+
+ with mock.patch("os.scandir") as scandir:
+ scandir.return_value = sorted(os.scandir(base))
+ self.assertEqual(len(set(base.glob("*"))), 3)
+
+ subdir.mkdir()
+
+ with mock.patch("os.scandir") as scandir:
+ scandir.return_value = sorted(os.scandir(base))
+ self.assertEqual(len(set(base.glob("*"))), 4)
+
+ subdir.chmod(000)
+
+ with mock.patch("os.scandir") as scandir:
+ scandir.return_value = sorted(os.scandir(base))
+ self.assertEqual(len(set(base.glob("*"))), 4)
def _check_resolve(self, p, expected, strict=True):
q = p.resolve(strict)