@@ -979,17 +979,40 @@ def test_realpath_permission(self):
979
979
except AssertionError :
980
980
raise unittest .SkipTest ('the filesystem seems to lack support for short filenames' )
981
981
982
- # Deny the right to [S]YNCHRONIZE on the file to
983
- # force nt._getfinalpathname to fail with ERROR_ACCESS_DENIED.
984
982
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 ,
987
986
)
988
-
989
987
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 :
990
1009
raise unittest .SkipTest ('failed to deny access to the test file' )
991
1010
992
1011
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 )
993
1016
994
1017
def test_expandvars (self ):
995
1018
with os_helper .EnvironmentVarGuard () as env :
0 commit comments