Checkpoint web parity through Chromium input tasks
This commit is contained in:
33
web/tests/unit/server-job-result-binding.test.mjs
Normal file
33
web/tests/unit/server-job-result-binding.test.mjs
Normal file
@@ -0,0 +1,33 @@
|
||||
import assert from "node:assert/strict";
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { commitServerJobResult, verifyServerJobResultReceipt } from "../../../tools/web/server-job-result-binding.mjs";
|
||||
|
||||
const h = (value) => crypto.createHash("sha256").update(value).digest("hex");
|
||||
const identity = { requestId: "request-1", projectId: "project-1", baseRevision: 7, sourceSha256: h("source"), settingsSha256: h("settings"), buildSha256: h("build") };
|
||||
|
||||
test("M13-04I commits only a readback-verified result and binds four identity hashes", async () => {
|
||||
const directory = await fs.mkdtemp(path.join(os.tmpdir(), "m13-04i-binding-"));
|
||||
try {
|
||||
const receipt = await commitServerJobResult(identity, new Uint8Array([1, 2, 3]), { outputDirectory: directory });
|
||||
assert.equal(receipt.status, "COMMITTED");
|
||||
assert.equal(receipt.publish, true);
|
||||
assert.equal((await verifyServerJobResultReceipt(receipt, identity, directory)).verified, true);
|
||||
assert.equal(receipt.outputByteLength, 3);
|
||||
} finally { await fs.rm(directory, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
test("M13-04I blocks tamper, stale identity and partial/quota failures", async () => {
|
||||
const directory = await fs.mkdtemp(path.join(os.tmpdir(), "m13-04i-negative-"));
|
||||
try {
|
||||
await assert.rejects(commitServerJobResult({ ...identity, settingsSha256: h("changed") }, new Uint8Array([1]), { outputDirectory: directory, expectedIdentity: identity, faultAt: "AFTER_STAGE" }), /SERVER_JOB_RESULT_IDENTITY_MISMATCH/);
|
||||
assert.deepEqual(await fs.readdir(directory), []);
|
||||
const receipt = await commitServerJobResult(identity, new Uint8Array([4, 5]), { outputDirectory: directory });
|
||||
await fs.writeFile(receipt.outputPath, new Uint8Array([9]));
|
||||
await assert.rejects(verifyServerJobResultReceipt(receipt, identity, directory), /SERVER_JOB_RESULT_HASH_MISMATCH/);
|
||||
await assert.rejects(commitServerJobResult({ ...identity, requestId: "request-2" }, new Uint8Array([8]), { outputDirectory: directory, faultAt: "QUOTA" }), /SERVER_JOB_RESULT_STORAGE_QUOTA/);
|
||||
} finally { await fs.rm(directory, { recursive: true, force: true }); }
|
||||
});
|
||||
Reference in New Issue
Block a user