]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118486: Simplify test_win32_mkdir_700 to check the exact ACL (GH-119056)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 15 May 2024 11:21:57 +0000 (13:21 +0200)
committerGitHub <noreply@github.com>
Wed, 15 May 2024 11:21:57 +0000 (11:21 +0000)
(cherry picked from commit 94591dca510c796c7d40e9b4167ea56f2fdf28ca)

Co-authored-by: Steve Dower <steve.dower@python.org>
Lib/test/test_os.py
Modules/posixmodule.c

index a64761c76d62fc3c4fd67602ff5b4497261cf162..6e895a587ea76f69fe091a24ed24c976f1fb8308 100644 (file)
@@ -1800,21 +1800,14 @@ class MakedirTests(unittest.TestCase):
     @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)
+        path = os.path.abspath(os.path.join(os_helper.TESTFN, 'dir'))
+        os.mkdir(path, mode=0o700)
+        out = subprocess.check_output(["cacls.exe", path, "/s"], encoding="oem")
+        os.rmdir(path)
+        self.assertEqual(
+            out.strip(),
+            f'{path} "D:P(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;FA;;;OW)"',
+        )
 
     def tearDown(self):
         path = os.path.join(os_helper.TESTFN, 'dir1', 'dir2', 'dir3',
index ebd076b4e44214d063976fa09694bd1a8bb7cb75..23cfcdeca246e11028a14fd48f17515439a75bad 100644 (file)
@@ -5364,7 +5364,7 @@ os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd)
     if (mode == 0700 /* 0o700 */) {
         ULONG sdSize;
         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
         // SYSTEM (SY), Administrators (BA), and the owner (OW).
         if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(