Skip to content

Commit 13c0c59

Browse files
committed
test: guard checksum-verified OpenGrep installation
1 parent 8a8082a commit 13c0c59

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

‎test/scripts/ci-workflow-guards.test.ts‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,24 +1778,39 @@ describe("ci workflow guards", () => {
17781778
}
17791779
});
17801780

1781-
it("downloads the opengrep installer completely before execution", () => {
1781+
it("verifies the pinned OpenGrep release binary before installing it", () => {
17821782
for (const workflowPath of [OPENGREP_PR_DIFF_WORKFLOW, OPENGREP_FULL_WORKFLOW]) {
17831783
const workflow = parse(readFileSync(workflowPath, "utf8"));
1784-
const run = expectDefined(
1785-
workflow.jobs.scan.steps.find((step: WorkflowStep) => step.name === "Install opengrep")
1786-
?.run,
1784+
const installStep = expectDefined(
1785+
workflow.jobs.scan.steps.find((step: WorkflowStep) => step.name === "Install opengrep"),
17871786
`Install opengrep step in ${workflowPath}`,
17881787
);
1788+
const run = expectDefined(installStep.run, `Install opengrep script in ${workflowPath}`);
17891789

1790+
expect(installStep.env, workflowPath).toMatchObject({
1791+
OPENGREP_VERSION: "v1.25.0",
1792+
OPENGREP_LINUX_X64_SHA256:
1793+
"9ac4aebb47ba3f7b0d8fc641ac8749cb6c2f253f616131a67d9631e00d4bea33",
1794+
});
1795+
expect(run, workflowPath).toContain('binary="$(mktemp "${RUNNER_TEMP}/opengrep.XXXXXX")"');
1796+
expect(run, workflowPath).toContain("trap 'rm -f \"$binary\"' EXIT");
1797+
expect(run, workflowPath).toContain(
1798+
"curl -fsSL --retry 4 --retry-all-errors --retry-delay 2",
1799+
);
1800+
expect(run, workflowPath).toContain("--connect-timeout 10 --max-time 300");
1801+
expect(run, workflowPath).toContain('-o "$binary"');
17901802
expect(run, workflowPath).toContain(
1791-
'installer="$(mktemp "${RUNNER_TEMP}/opengrep-install.XXXXXX")"',
1803+
"https://github.com/opengrep/opengrep/releases/download/${OPENGREP_VERSION}/opengrep_manylinux_x86",
1804+
);
1805+
expect(run, workflowPath).toContain(
1806+
'printf \'%s %s\\n\' "$OPENGREP_LINUX_X64_SHA256" "$binary" | sha256sum --check',
1807+
);
1808+
expect(run, workflowPath).toContain('install -m 0755 "$binary" "$install_dir/opengrep"');
1809+
expect(run.indexOf('-o "$binary"'), workflowPath).toBeLessThan(
1810+
run.indexOf("sha256sum --check"),
17921811
);
1793-
expect(run, workflowPath).toContain("curl -fsSL --connect-timeout 10 --max-time 120 \\");
1794-
expect(run, workflowPath).toContain('-o "$installer"');
1795-
expect(run, workflowPath).toContain('bash "$installer" -v "$OPENGREP_VERSION"');
1796-
expect(run, workflowPath).toContain("trap 'rm -f \"$installer\"' EXIT");
1797-
expect(run.indexOf('-o "$installer"'), workflowPath).toBeLessThan(
1798-
run.indexOf('bash "$installer"'),
1812+
expect(run.indexOf("sha256sum --check"), workflowPath).toBeLessThan(
1813+
run.indexOf('install -m 0755 "$binary"'),
17991814
);
18001815
expect(run, workflowPath).not.toMatch(/\|\s*bash/u);
18011816
}

0 commit comments

Comments
 (0)