@@ -6,6 +6,7 @@ import test from "ava";
66
77import { scanArtifactsForTokens } from "./artifact-scanner" ;
88import { getRunnerLogger } from "./logging" ;
9+ import { getRecordingLogger , LoggedMessage } from "./testing-utils" ;
910
1011test ( "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+ / F o u n d .* p o t e n t i a l G i t H u b t o k e n / ,
82+ "Should detect token in nested zip" ,
83+ ) ;
84+ t . regex (
85+ error ?. message || "" ,
86+ / k o t l i n \. 9 0 1 7 2 3 1 6 5 2 9 8 9 7 4 4 3 1 9 \. t r a p / ,
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+ / ^ E x t r a c t i n g g z f i l e : .* \. g z $ / m,
94+ "Logs should show that .gz files were extracted" ,
95+ ) ;
96+ } ) ;
0 commit comments