8000 gh-114435: Add test skip when running as admin. · zooba/cpython@c08870c · GitHub
[go: up one dir, main page]

Skip to content

Commit c08870c

Browse files
committed
pythongh-114435: Add test skip when running as admin.
Also makes _winapi.CreateFile unconditionally use Unicode.
1 parent 841eacd commit c08870c

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

Lib/test/test_os.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,6 +3122,23 @@ def cleanup():
31223122
print("File:", filename)
31233123
print("stat with access:", stat1)
31243124

3125+
# We should now not be able to open the file.
3126+
# If we can, the test isn't going to be useful.
3127+
try:
3128+
_winapi.CloseHandle(_winapi.CreateFile(
3129+
filename,
3130+
0x80, # FILE_READ_ATTRIBUTES
3131+
0,
3132+
0,
3133+
_winapi.OPEN_EXISTING,
3134+
0x02000000, # FILE_FLAG_BACKUP_SEMANTICS
3135+
0,
3136+
))
3137+
except PermissionError:
3138+
pass
3139+
else:
3140+
self.skipTest("Still had access to inaccessible file")
3141+
31253142
# First test - we shouldn't raise here, because we still have access to
31263143
# the directory and can extract enough information from its metadata.
31273144
stat2 = os.stat(filename)

Modules/_winapi.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ _winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle,
441441
/*[clinic input]
442442
_winapi.CreateFile -> HANDLE
443443
444-
file_name: LPCTSTR
444+
file_name: LPCWSTR
445445
desired_access: DWORD
446446
share_mode: DWORD
447447
security_attributes: LPSECURITY_ATTRIBUTES
@@ -452,12 +452,12 @@ _winapi.CreateFile -> HANDLE
452452
[clinic start generated code]*/
453453

454454
static HANDLE
455-
_winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name,
455+
_winapi_CreateFile_impl(PyObject *module, LPCWSTR file_name,
456456
DWORD desired_access, DWORD share_mode,
457457
LPSECURITY_ATTRIBUTES security_attributes,
458458
DWORD creation_disposition,
459459
DWORD flags_and_attributes, HANDLE template_file)
460-
/*[clinic end generated code: output=417ddcebfc5a3d53 input=6423c3e40372dbd5]*/
460+
/*[clinic end generated code: output=818c811e5e04d550 input=1fa870ed1c2e3d69]*/
461461
{
462462
HANDLE handle;
463463

@@ -468,14 +468,15 @@ _winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name,
468468
}
469469

470470
Py_BEGIN_ALLOW_THREADS
471-
handle = CreateFile(file_name, desired_access,
472-
share_mode, security_attributes,
473-
creation_disposition,
474-
flags_and_attributes, template_file);
471+
handle = CreateFileW(file_name, desired_access,
472+
share_mode, security_attributes,
473+
creation_disposition,
474+
flags_and_attributes, template_file);
475475
Py_END_ALLOW_THREADS
476476

477-
if (handle == INVALID_HANDLE_VALUE)
477+
if (handle == INVALID_HANDLE_VALUE) {
478478
PyErr_SetFromWindowsErr(0);
479+
}
479480

480481
return handle;
481482
}

Modules/clinic/_winapi.c.h

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0