Files
rust-discovery/web/src/system-nonstart-review.test.ts
T
2026-11-16 17:46:54 +01:00

23 lines
2.6 KiB
TypeScript

import { expect, it } from 'vitest';
import { canonicalJson } from './api';
import { sha256 } from './safety';
import { nonstartReview } from './system-nonstart-review';
it('binds the exact 221 witness and refuses job authority, altered history and extended receipts', async () => {
const witness = { schema_version: 1, tenant_id: '11111111-1111-4111-8111-111111111111', asset_id: 'a176520e-8a91-4e93-a78b-8e7620f430e0', agent_id: '63ea15b2-0643-403d-b5b4-cba1288dbea3',
enrollment_generation: 1, assignment_version: 1, connection_generation: 221, boot_id: 'a9ad0895-5a96-8f2c-8fb6-cfdc2d5225ea', agent_checkpoint: 10784, helper_checkpoint: 420,
agent_last_decision: '0442c732-8226-4c25-9615-7f007e24b269', helper_last_decision: '193b951b-a3aa-46e2-9f48-1a57f315078e', verification_key_id: 'a'.repeat(64),
nonstart: { helper_pid: 1304, read_share_error: 32, read_write_share_passed: true, helper_image_sha256: '0502d6c87bd74c99f1665f3cc4b9d74b8e31d0f829d2ce1a1597d72e9be1e726', system_script_source_sha256: 'a3563e1aa8327b2e7046c7cdfb4f45ac213fec6ff7d477820ea2676a266c1695' },
counts: { agent_jobs: 4, agent_consumed: 3, agent_starts: 3, agent_outcomes: 3, helper_consumed: 1, helper_starts: 1, helper_outcomes: 1, system_intents: 1 } };
const witness_sha256 = await sha256(new TextEncoder().encode(canonicalJson(witness)));
const request_id = '78009224-dcb3-4877-a519-8bf3284d0572';
const receipt = { domain: 'rmm.dev.windows-system-nonstart-221.v1', schema_version: 1, request_id, server_transport_generation:287, witness, witness_sha256, key_id: witness.verification_key_id,
issued_at: '2026-11-16T12:00:00Z', valid_until: '2026-11-16T12:05:00Z', confirmed_by: 'simulated-testprincipal-a', approval_origin: 'dev_test_browser_simulation', testsimulation: true, ready: false, helper_ready: false, unlock: false };
const view = { request_id, server_transport_generation:287, witness, witness_sha256, receipt };
expect((await nonstartReview(view)).witness_sha256).toBe(witness_sha256);
for (const changed of [{ ready: true }, { helper_ready: true }, { unlock: true }, { testsimulation: false }, { confirmed_by: 'Administrator' }, { valid_until: '2026-11-16T12:05:01Z' }, { witness: { ...witness, helper_checkpoint: 412 } }]) {
await expect(nonstartReview({ ...view, receipt: { ...receipt, ...changed } })).rejects.toThrow();
}
await expect(nonstartReview({ ...view, witness: { ...witness, connection_generation: 205 } })).rejects.toThrow();
await expect(nonstartReview({ ...view, witness: { ...witness, counts: { ...witness.counts, helper_consumed: 2 } } })).rejects.toThrow();
});