Skip to content

Commit 488c1f1

Browse files
committed
Add regression test for artifact scanner
1 parent f2ccf3b commit 488c1f1

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/artifact-scanner.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import test from "ava";
66

77
import { scanArtifactsForTokens } from "./artifact-scanner";
88
import { getRunnerLogger } from "./logging";
9+
import { getRecordingLogger, LoggedMessage } from "./testing-utils";
910

1011
test("scanArtifactsForTokens detects GitHub tokens in files", async (t) => {
1112
const logger = getRunnerLogger(true);
@@ -54,3 +55,42 @@ test("scanArtifactsForTokens handles files without tokens", async (t) => {
5455
fs.rmSync(tempDir, { recursive: true, force: true });
5556
}
5657
});
58+
59+
test("scanArtifactsForTokens finds token in debug artifacts", async (t) => {
60+
t.timeout(30000); // 30 seconds
61+
const messages: LoggedMessage[] = [];
62+
const logger = getRecordingLogger(messages);
63+
// The zip here is a regression test based on
64+
// https://github.com/github/codeql-action/security/advisories/GHSA-vqf5-2xx6-9wfm
65+
const testZip = path.join(
66+
__dirname,
67+
"..",
68+
"src",
69+
"testdata",
70+
"debug-artifacts-with-fake-token.zip",
71+
);
72+
73+
// This zip file contains a nested structure with a fake token in:
74+
// my-db-java-partial.zip/trap/java/invocations/kotlin.9017231652989744319.trap
75+
const error = await t.throwsAsync(
76+
async () => await scanArtifactsForTokens([testZip], logger),
77+
);
78+
79+
t.regex(
80+
error?.message || "",
81+
/Found.*potential GitHub token/,
82+
"Should detect token in nested zip",
83+
);
84+
t.regex(
85+
error?.message || "",
86+
/kotlin\.9017231652989744319\.trap/,
87+
"Should report the .trap file containing the token",
88+
);
89+
90+
const logOutput = messages.map((msg) => msg.message).join("\n");
91+
t.regex(
92+
logOutput,
93+
/^Extracting gz file: .*\.gz$/m,
94+
"Logs should show that .gz files were extracted",
95+
);
96+
});
990 KB
Binary file not shown.

0 commit comments

Comments
 (0)