Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion scripts/release-publication-receipt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ function requireRegularFile(path, label, maxBytes = MAX_JSON_BYTES) {

function readJson(path, label) {
requireRegularFile(path, label);
let text;
try {
const value = JSON.parse(readFileSync(path, "utf8"));
text = new TextDecoder("utf-8", { fatal: true }).decode(readFileSync(path));
} catch (error) {
fail(`${label} is not valid UTF-8: ${error instanceof Error ? error.message : String(error)}`);
}
try {
const value = JSON.parse(text);
if (!value || typeof value !== "object" || Array.isArray(value)) {
fail(`${label} must contain a JSON object`);
}
Expand Down
24 changes: 23 additions & 1 deletion test/immutable-release-publication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,28 @@ describe("immutable buyer release publication", () => {
}
});

it("fails closed on malformed UTF-8 publication JSON", () => {
const temp = mkdtempSync(join(tmpdir(), "noema-immutable-release-invalid-utf8-"));
try {
const { fixture, result } = runReceipt(temp, (value) => {
writeFileSync(
value.policyPath,
Buffer.concat([
Buffer.from('{"enabled":true,"enforced_by_owner":true,"evidence_note":"', "utf8"),
Buffer.from([0x80]),
Buffer.from('"}', "utf8"),
]),
);
});

expect(result.status).not.toBe(0);
expect(result.stderr).toContain("UTF-8");
expect(() => readFileSync(fixture.outputPath)).toThrow();
} finally {
rmSync(temp, { recursive: true, force: true });
}
});

it("isolates publication permission and verifies every durable release asset", () => {
const workflow = readFileSync(".github/workflows/release-evidence.yml", "utf8");

Expand Down Expand Up @@ -308,4 +330,4 @@ describe("immutable buyer release publication", () => {
expect(documentation).toContain("gh release verify-asset");
expect(documentation).toContain("does not prove deployment");
});
});
});
Loading