feat: verify frontend supply chain
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { cp, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
const fixtureRoot = await mkdtemp(
|
||||
path.join(tmpdir(), "ca-frontend-frozen-lockfile-"),
|
||||
);
|
||||
try {
|
||||
await cp("pnpm-lock.yaml", path.join(fixtureRoot, "pnpm-lock.yaml"));
|
||||
const manifest = JSON.parse(await readFile("package.json", "utf8"));
|
||||
manifest.dependencies.react = "0.0.0-invalid-fixture";
|
||||
await writeFile(
|
||||
path.join(fixtureRoot, "package.json"),
|
||||
`${JSON.stringify(manifest, null, 2)}\n`,
|
||||
);
|
||||
const result = spawnSync(
|
||||
"corepack",
|
||||
[
|
||||
"pnpm",
|
||||
"install",
|
||||
"--frozen-lockfile",
|
||||
"--lockfile-only",
|
||||
"--ignore-scripts",
|
||||
],
|
||||
{
|
||||
cwd: fixtureRoot,
|
||||
encoding: "utf8",
|
||||
},
|
||||
);
|
||||
if (result.status === 0) {
|
||||
process.stderr.write("Tampered manifest unexpectedly passed frozen install.\n");
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
process.stdout.write("Frozen lockfile mismatch fixture: rejected PASS\n");
|
||||
}
|
||||
} finally {
|
||||
await rm(fixtureRoot, { recursive: true, force: true });
|
||||
}
|
||||
Reference in New Issue
Block a user