summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2024-05-02 14:20:43 (GMT)
committerGitHub <noreply@github.com>2024-05-02 14:20:43 (GMT)
commit81939dad77001556c527485d31a2d0f4a759033e (patch)
treec494f3abbfdc01dc931ef6edcaa9ed4bf0480951 /Lib
parentb3372481b6cae5766330b041c4622c28cee2119f (diff)
downloadcpython-81939dad77001556c527485d31a2d0f4a759033e.zip
cpython-81939dad77001556c527485d31a2d0f4a759033e.tar.gz
cpython-81939dad77001556c527485d31a2d0f4a759033e.tar.bz2
gh-118486: Support mkdir(mode=0o700) on Windows (GH-118488)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_os.py19
-rw-r--r--Lib/test/test_tempfile.py28
2 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index eaa6766..9c9c853 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1811,6 +1811,25 @@ class MakedirTests(unittest.TestCase):
self.assertRaises(OSError, os.makedirs, path, exist_ok=True)
os.remove(path)
+ @unittest.skipUnless(os.name == 'nt', "requires Windows")
+ def test_win32_mkdir_700(self):
+ base = os_helper.TESTFN
+ path1 = os.path.join(os_helper.TESTFN, 'dir1')
+ path2 = os.path.join(os_helper.TESTFN, 'dir2')
+ # mode=0o700 is special-cased to override ACLs on Windows
+ # There's no way to know exactly how the ACLs will look, so we'll
+ # check that they are different from a regularly created directory.
+ os.mkdir(path1, mode=0o700)
+ os.mkdir(path2, mode=0o777)
+
+ out1 = subprocess.check_output(["icacls.exe", path1], encoding="oem")
+ out2 = subprocess.check_output(["icacls.exe", path2], encoding="oem")
+ os.rmdir(path1)
+ os.rmdir(path2)
+ out1 = out1.replace(path1, "<PATH>")
+ out2 = out2.replace(path2, "<PATH>")
+ self.assertNotEqual(out1, out2)
+
def tearDown(self):
path = os.path.join(os_helper.TESTFN, 'dir1', 'dir2', 'dir3',
'dir4', 'dir5', 'dir6')
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index b64b6a4..19ddeaa 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -13,6 +13,7 @@ import types
import weakref
import gc
import shutil
+import subprocess
from unittest import mock
import unittest
@@ -803,6 +804,33 @@ class TestMkdtemp(TestBadTempdir, BaseTestCase):
finally:
os.rmdir(dir)
+ @unittest.skipUnless(os.name == "nt", "Only on Windows.")
+ def test_mode_win32(self):
+ # Use icacls.exe to extract the users with some level of access
+ # Main thing we are testing is that the BUILTIN\Users group has
+ # no access. The exact ACL is going to vary based on which user
+ # is running the test.
+ dir = self.do_create()
+ try:
+ out = subprocess.check_output(["icacls.exe", dir], encoding="oem").casefold()
+ finally:
+ os.rmdir(dir)
+
+ dir = dir.casefold()
+ users = set()
+ found_user = False
+ for line in out.strip().splitlines():
+ acl = None
+ # First line of result includes our directory
+ if line.startswith(dir):
+ acl = line.removeprefix(dir).strip()
+ elif line and line[:1].isspace():
+ acl = line.strip()
+ if acl:
+ users.add(acl.partition(":")[0])
+
+ self.assertNotIn(r"BUILTIN\Users".casefold(), users)
+
def test_collision_with_existing_file(self):
# mkdtemp tries another name when a file with
# the chosen name already exists