Skip to content

Commit 45433ca

Browse files
committed
test: verify uiAccess token in CI; remove co_await from task.RequestEnableAsync temporarily
1 parent a81ad55 commit 45433ca

2 files changed

Lines changed: 55 additions & 6 deletions

File tree

scripts/exitcode_smoke.ps1

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
# On any timeout the script enumerates every window the process owns and writes a full
2828
# minidump of the LIVE process into -DumpDir (defaults to $env:WER_DUMP_DIR) before killing
2929
# it, so a hang is as diagnosable as a crash.
30-
#
31-
# The exe must be launchable in the calling environment. A uiAccess-manifested build will not
32-
# launch AT ALL where UAC is disabled (GitHub-hosted runners: EnableLUA=0 means Windows
33-
# cannot mint a UIAccess token, so CreateProcess fails outright) — the CI workflow strips
34-
# uiAccess from the binary first. On a normal desktop, point this at any signed build.
3530

3631
param(
3732
# Exactly one of these. -ExePath launches a loose exe (note: outside a secure path a
@@ -133,6 +128,43 @@ public static class ClippSmoke
133128
[DllImport("dbghelp.dll", SetLastError = true)]
134129
public static extern bool MiniDumpWriteDump(IntPtr hProcess, uint ProcessId, IntPtr hFile,
135130
int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);
131+
132+
[DllImport("kernel32.dll", SetLastError = true)]
133+
static extern IntPtr OpenProcess(uint access, bool inherit, uint pid);
134+
[DllImport("advapi32.dll", SetLastError = true)]
135+
static extern bool OpenProcessToken(IntPtr hProcess, uint access, out IntPtr hToken);
136+
[DllImport("advapi32.dll", SetLastError = true)]
137+
static extern bool GetTokenInformation(IntPtr hToken, int infoClass, out uint info, uint len, out uint retLen);
138+
[DllImport("kernel32.dll")]
139+
static extern bool CloseHandle(IntPtr h);
140+
141+
// Whether the process token carries the UIAccess flag (TokenUIAccess, class 26) — i.e.
142+
// Windows actually granted the manifest's uiAccess request, the configuration whose
143+
// faults this test exists to catch. Opens its own PROCESS_QUERY_LIMITED_INFORMATION
144+
// handle: that right is grantable across the UIPI/integrity boundary a UIAccess target
145+
// sits behind, where the PROCESS_ALL_ACCESS handle .NET's Process.Handle wants is not.
146+
// Returns 1 (granted), 0 (not granted), or the negated Win32 error on failure.
147+
public static int GetUIAccess(uint pid)
148+
{
149+
IntPtr proc = OpenProcess(0x1000 /* PROCESS_QUERY_LIMITED_INFORMATION */, false, pid);
150+
if (proc == IntPtr.Zero)
151+
return -Marshal.GetLastWin32Error();
152+
IntPtr token = IntPtr.Zero;
153+
try
154+
{
155+
if (!OpenProcessToken(proc, 0x0008 /* TOKEN_QUERY */, out token))
156+
return -Marshal.GetLastWin32Error();
157+
uint val, len;
158+
if (!GetTokenInformation(token, 26 /* TokenUIAccess */, out val, 4, out len))
159+
return -Marshal.GetLastWin32Error();
160+
return val != 0 ? 1 : 0;
161+
}
162+
finally
163+
{
164+
if (token != IntPtr.Zero) CloseHandle(token);
165+
CloseHandle(proc);
166+
}
167+
}
136168
}
137169
138170
// Packaged-app activation. shell:AppsFolder via Start-Process hands off to the AppX broker
@@ -236,6 +268,22 @@ if ($PSCmdlet.ParameterSetName -eq 'Package') {
236268
$p = Start-Process -FilePath $ExePath -PassThru
237269
}
238270

271+
# Report whether Windows actually granted the manifest's uiAccess request. Without the token
272+
# a green run says nothing about the uiAccess configuration winget validates — the packaged
273+
# case warns loudly rather than failing, so the exit-code reading below still happens.
274+
$ui = [ClippSmoke]::GetUIAccess([uint32]$p.Id)
275+
if ($ui -eq 1) {
276+
Write-Host 'UIAccess token: GRANTED'
277+
} elseif ($ui -eq 0) {
278+
if ($PSCmdlet.ParameterSetName -eq 'Package') {
279+
Write-Host '::warning::UIAccess token NOT granted to the packaged app — this run does not exercise the uiAccess configuration winget validates.'
280+
} else {
281+
Write-Host 'UIAccess token: not granted (expected for a loose exe outside a secure path).'
282+
}
283+
} else {
284+
Write-Host ("UIAccess token: unreadable (Win32 {0})" -f (-$ui))
285+
}
286+
239287
# On a clean profile (no group key) Clipp opens its main XAML-Islands window unprompted.
240288
# Islands cold-start can be slow on a runner, hence the generous timeout.
241289
$dialog = [IntPtr]::Zero

src/platform/win32/AutoStart.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ namespace {
7373
try {
7474
co_await winrt::resume_background();
7575
auto task = co_await winrt::Windows::ApplicationModel::StartupTask::GetAsync(kStartupTaskId);
76-
co_await task.RequestEnableAsync();
76+
// TEMPORARY REMOVAL TO REPRO 0xC000027B ON GH CI
77+
/*co_await*/ task.RequestEnableAsync();
7778
}
7879
catch (...) {
7980
}

0 commit comments

Comments
 (0)