Skip to content

Commit fd2013a

Browse files
committed
Attempt to restore ntpath test
1 parent f845343 commit fd2013a

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

Lib/test/test_ntpath.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,17 +979,40 @@ def test_realpath_permission(self):
979979
except AssertionError:
980980
raise unittest.SkipTest('the filesystem seems to lack support for short filenames')
981981

982-
# Deny the right to [S]YNCHRONIZE on the file to
983-
# force nt._getfinalpathname to fail with ERROR_ACCESS_DENIED.
984982
p = subprocess.run(
985-
['icacls.exe', test_file, '/deny', '*S-1-5-32-545:(S)'],
986-
creationflags=subprocess.DETACHED_PROCESS
983+
['whoami.exe', '/GROUPS'],
984+
creationflags=subprocess.DETACHED_PROCESS,
985+
capture_output=True,
987986
)
988-
989987
if p.returncode:
988+
raise unittest.SkipTest('cannot check group membership')
989+
990+
groups_output = p.stdout
991+
groups = (
992+
'S-1-5-32-544', # Administrators
993+
'S-1-5-32-545', # Users
994+
)
995+
996+
for group in groups:
997+
if group.encode() not in groups_output:
998+
continue
999+
1000+
# Deny the right to [S]YNCHRONIZE on the file to
1001+
# force nt._getfinalpathname to fail with ERROR_ACCESS_DENIED.
1002+
p = subprocess.run(
1003+
['icacls.exe', test_file, '/deny', f'*{group}:(S)'],
1004+
creationflags=subprocess.DETACHED_PROCESS
1005+
)
1006+
if p.returncode == 0:
1007+
break
1008+
else:
9901009
raise unittest.SkipTest('failed to deny access to the test file')
9911010

9921011
self.assertPathEqual(test_file, ntpath.realpath(test_file_short))
1012+
with self.assertRaises(OSError):
1013+
ntpath.realpath(test_file_short, strict=True)
1014+
with self.assertRaises(OSError):
1015+
ntpath.realpath(test_file_short, strict=ALLOW_MISSING)
9931016

9941017
def test_expandvars(self):
9951018
with os_helper.EnvironmentVarGuard() as env:

0 commit comments

Comments
 (0)