gh-118486: Simplify test_win32_mkdir_700 to check the exact ACL (GH-119056)

(cherry picked from commit 94591dca510c796c7d40e9b4167ea56f2fdf28ca)

Co-authored-by: Steve Dower <steve.dower@python.org>
This commit is contained in:
Miss Islington (bot) 2024-05-15 13:21:27 +02:00 • committed by GitHub
parent dd8a61f901
commit e1dfa978b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 16 deletions

View file

@ -1814,21 +1814,14 @@ class MakedirTests(unittest.TestCase):
@unittest.skipUnless(os.name == 'nt', "requires Windows") @unittest.skipUnless(os.name == 'nt', "requires Windows")
def test_win32_mkdir_700(self): def test_win32_mkdir_700(self):
base = os_helper.TESTFN base = os_helper.TESTFN
path1 = os.path.join(os_helper.TESTFN, 'dir1') path = os.path.abspath(os.path.join(os_helper.TESTFN, 'dir'))
path2 = os.path.join(os_helper.TESTFN, 'dir2') os.mkdir(path, mode=0o700)
# mode=0o700 is special-cased to override ACLs on Windows out = subprocess.check_output(["cacls.exe", path, "/s"], encoding="oem")
# There's no way to know exactly how the ACLs will look, so we'll os.rmdir(path)
# check that they are different from a regularly created directory. self.assertEqual(
os.mkdir(path1, mode=0o700) out.strip(),
os.mkdir(path2, mode=0o777) f'{path} "D:P(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;FA;;;OW)"',
)
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): def tearDown(self):
path = os.path.join(os_helper.TESTFN, 'dir1', 'dir2', 'dir3', path = os.path.join(os_helper.TESTFN, 'dir1', 'dir2', 'dir3',

View file

@ -5590,7 +5590,7 @@ os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd)
if (mode == 0700 /* 0o700 */) { if (mode == 0700 /* 0o700 */) {
ULONG sdSize; ULONG sdSize;
pSecAttr = &secAttr; pSecAttr = &secAttr;
// Set a discreationary ACL (D) that is protected (P) and includes // Set a discretionary ACL (D) that is protected (P) and includes
// inheritable (OICI) entries that allow (A) full control (FA) to // inheritable (OICI) entries that allow (A) full control (FA) to
// SYSTEM (SY), Administrators (BA), and the owner (OW). // SYSTEM (SY), Administrators (BA), and the owner (OW).
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW( if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(