mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-118486: Support mkdir(mode=0o700) on Windows (GH-118488)
This commit is contained in:
parent
b3372481b6
commit
81939dad77
5 changed files with 212 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue