gh-118486: Support mkdir(mode=0o700) on Windows (GH-118488)

This commit is contained in:
Steve Dower 2024-05-02 15:20:43 +01:00 committed by GitHub
parent b3372481b6
commit 81939dad77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 212 additions and 2 deletions

View file

@ -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