Validate the full Windows Update plan through its fixed script revision

This commit is contained in:
2026-11-17 17:40:42 +01:00
parent 4f69312bef
commit c94c3939f1
4 changed files with 47 additions and 31 deletions
+14 -4
View File
@@ -53,22 +53,32 @@ it('shows the immutable library revision and rejects a different catalog script
it('accepts one hour only for the exact Windows Update revision', async () => {
const source = readFileSync(new URL('../../crates/domain/src/windows_update.ps1', import.meta.url), 'utf8');
async function windowPlan(script: string, fixed: boolean, seconds: number) {
async function windowPlan(script: string, fixed: boolean, seconds: number, args: string[] = [], expected: string | null = null, claimedHash?: string) {
const original = plan('windows_system_full');
const parsed = record(JSON.parse(new TextDecoder().decode(new Uint8Array(original.plan_payload_bytes as number[]))));
const job = (parsed.jobs as RecordValue[])[0]!, payload = record(job.payload), action = record(payload.action);
action.script_utf8 = script; action.arguments = []; action.expected_stdout = null; payload.max_runtime_seconds = seconds;
action.script_utf8 = script; action.arguments = args; action.expected_stdout = expected; payload.max_runtime_seconds = seconds;
job.script_sha256 = await sha256(new TextEncoder().encode(script));
if (claimedHash) job.script_sha256 = claimedHash;
job.job_payload_hash = await sha256(new TextEncoder().encode(JSON.stringify(payload)));
if (fixed) parsed.script_revision = { revision_id: parsed.plan_id, name: 'Windows-Updates installieren', version: 1, script_sha256: job.script_sha256 };
const raw = new TextEncoder().encode(JSON.stringify(parsed));
return { plan_hash: await sha256(raw), plan_payload_bytes: Array.from(raw) };
}
const valid = await windowPlan(source, true, 3600);
await verifyScriptPlan(valid); expect(scriptPlanJobs(valid)[0]?.runtimeSeconds).toBe(3600);
for (const bad of [await windowPlan(source+'\n',true,3600), await windowPlan(source,false,3600), await windowPlan(source,true,3601)]) {
await verifyPlanIntegrity(valid); await verifyScriptPlan(valid);
expect(scriptPlanJobs(valid)[0]?.runtimeSeconds).toBe(3600);
const templateHash = await sha256(new TextEncoder().encode(source));
for (const bad of [
await windowPlan(source+'\n',true,3600), await windowPlan(source,false,3600),
await windowPlan(source,true,3601), await windowPlan(source,true,3600,['x']),
await windowPlan(source,true,3600,[],'unexpected'),
await windowPlan('Write-Output 1',true,121,[],null,templateHash)
]) {
await expect(verifyPlanIntegrity(bad)).rejects.toThrow();
await expect(verifyScriptPlan(bad)).rejects.toThrow();
}
await verifyPlanIntegrity(await windowPlan('Write-Output 1',true,120));
});
it('rejects view, byte and fixed identity/budget/profile tampering before and after display', async () => {