Repository navigation
fix(governance): restack fatal UTF-8 production evidence on 293e338 main #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
3d29ef9
efd4bd4
5feba68
5c37a5f
37a0aee
afba3a1
5e1db59
3e92c71
fc7cecf
ede6fcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { | ||
| decodeGhOutput, | ||
| runGh, | ||
| } from "../scripts/production-environment-governance-audit.mjs"; | ||
|
|
||
| function failureMessage(action: () => unknown) { | ||
| try { | ||
| action(); | ||
| } catch (error) { | ||
| return error instanceof Error ? error.message : String(error); | ||
| } | ||
| throw new Error("expected action to fail"); | ||
| } | ||
|
|
||
| describe("production environment governance GitHub CLI UTF-8 boundary", () => { | ||
| it("rejects malformed UTF-8 instead of replacement-decoding production evidence", () => { | ||
| expect(() => | ||
| decodeGhOutput( | ||
| Uint8Array.from([0x7b, 0x22, 0xff, 0x22, 0x7d]), | ||
| "stdout", | ||
| ), | ||
| ).toThrow("GitHub CLI returned invalid UTF-8 in stdout."); | ||
| }); | ||
|
|
||
| it("decodes valid UTF-8 bytes exactly", () => { | ||
| const bytes = new TextEncoder().encode('{"name":"production"}\n'); | ||
| expect(decodeGhOutput(bytes, "stdout")).toBe('{"name":"production"}\n'); | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| }); | ||
|
|
||
| it("prefers stderr and redacts GH_TOKEN on the real runGh failure path", () => { | ||
| const token = "read-only-secret-token"; | ||
| const message = failureMessage(() => | ||
| runGh(["api", "example"], { | ||
| sourceEnvironment: { PATH: "/usr/bin:/bin", GH_TOKEN: token }, | ||
| spawnSyncImpl: () => ({ | ||
| status: 1, | ||
| stdout: Buffer.from(`stdout exposed ${token}`, "utf8"), | ||
| stderr: Buffer.from(`stderr exposed ${token}`, "utf8"), | ||
| }), | ||
| }), | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| ); | ||
|
|
||
| expect(message).toBe("GitHub CLI failed: stderr exposed [REDACTED]"); | ||
|
Check failure on line 45 in test/production-environment-governance-utf8.test.ts
|
||
| expect(message).not.toContain(token); | ||
| expect(message).not.toContain("stdout exposed"); | ||
| }); | ||
|
|
||
| it("falls back to stdout and redacts GH_TOKEN when stderr is empty", () => { | ||
| const token = "read-only-secret-token"; | ||
| const message = failureMessage(() => | ||
| runGh(["api", "example"], { | ||
| sourceEnvironment: { PATH: "/usr/bin:/bin", GH_TOKEN: token }, | ||
| spawnSyncImpl: () => ({ | ||
| status: 1, | ||
| stdout: Buffer.from(`stdout exposed ${token}`, "utf8"), | ||
| stderr: Buffer.alloc(0), | ||
| }), | ||
| }), | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| ); | ||
|
|
||
| expect(message).toBe("GitHub CLI failed: stdout exposed [REDACTED]"); | ||
|
Check failure on line 63 in test/production-environment-governance-utf8.test.ts
|
||
| expect(message).not.toContain(token); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ["stderr", Buffer.from([0xff]), Buffer.from("valid stdout", "utf8")], | ||
| ["stdout", Buffer.alloc(0), Buffer.from([0xff])], | ||
| ] as const)("fails closed on malformed %s bytes from runGh", (label, stderr, stdout) => { | ||
| expect(() => | ||
| runGh(["api", "example"], { | ||
| sourceEnvironment: { PATH: "/usr/bin:/bin", GH_TOKEN: "secret" }, | ||
| spawnSyncImpl: () => ({ status: 1, stdout, stderr }), | ||
| }), | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| ).toThrow(`GitHub CLI returned invalid UTF-8 in ${label}.`); | ||
|
Check failure on line 76 in test/production-environment-governance-utf8.test.ts
|
||
| }); | ||
| }); | ||
|
seonghobae marked this conversation as resolved.
Resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.