@@ -49,7 +49,11 @@ func Test_SAST(t *testing.T) {
4949 name : "SAST checker should return min score when no PRs are found" ,
5050 commits : []clients.Commit {},
5151 searchresult : clients.SearchResponse {},
52- checkRuns : []clients.CheckRun {},
52+ searchRequest : clients.SearchRequest {
53+ Query : "github/codeql-action/analyze" ,
54+ Path : "/.github/workflows" ,
55+ },
56+ checkRuns : []clients.CheckRun {},
5357 expected : scut.TestReturn {
5458 Score : checker .MinResultScore ,
5559 NumberOfWarn : 1 ,
@@ -60,7 +64,11 @@ func Test_SAST(t *testing.T) {
6064 err : errors .New ("error" ),
6165 commits : []clients.Commit {},
6266 searchresult : clients.SearchResponse {},
63- checkRuns : []clients.CheckRun {},
67+ searchRequest : clients.SearchRequest {
68+ Query : "github/codeql-action/analyze" ,
69+ Path : "/.github/workflows" ,
70+ },
71+ checkRuns : []clients.CheckRun {},
6472 expected : scut.TestReturn {
6573 Score : checker .InconclusiveResultScore ,
6674 Error : sce .ErrScorecardInternal ,
@@ -76,6 +84,10 @@ func Test_SAST(t *testing.T) {
7684 },
7785 },
7886 searchresult : clients.SearchResponse {},
87+ searchRequest : clients.SearchRequest {
88+ Query : "github/codeql-action/analyze" ,
89+ Path : "/.github/workflows" ,
90+ },
7991 checkRuns : []clients.CheckRun {
8092 {
8193 Status : "completed" ,
@@ -101,6 +113,10 @@ func Test_SAST(t *testing.T) {
101113 },
102114 },
103115 searchresult : clients.SearchResponse {},
116+ searchRequest : clients.SearchRequest {
117+ Query : "github/codeql-action/analyze" ,
118+ Path : "/.github/workflows" ,
119+ },
104120 checkRuns : []clients.CheckRun {
105121 {
106122 Status : "completed" ,
@@ -126,6 +142,10 @@ func Test_SAST(t *testing.T) {
126142 },
127143 },
128144 searchresult : clients.SearchResponse {},
145+ searchRequest : clients.SearchRequest {
146+ Query : "github/codeql-action/analyze" ,
147+ Path : "/.github/workflows" ,
148+ },
129149 checkRuns : []clients.CheckRun {
130150 {
131151 Status : "completed" ,
@@ -152,6 +172,10 @@ func Test_SAST(t *testing.T) {
152172 },
153173 },
154174 searchresult : clients.SearchResponse {},
175+ searchRequest : clients.SearchRequest {
176+ Query : "github/codeql-action/analyze" ,
177+ Path : "/.github/workflows" ,
178+ },
155179 checkRuns : []clients.CheckRun {
156180 {
157181 Status : "completed" ,
@@ -178,7 +202,11 @@ func Test_SAST(t *testing.T) {
178202 },
179203 },
180204 searchresult : clients.SearchResponse {},
181- path : ".github/workflows/airflow-codeql-workflow.yaml" ,
205+ searchRequest : clients.SearchRequest {
206+ Query : "github/codeql-action/analyze" ,
207+ Path : "/.github/workflows" ,
208+ },
209+ path : ".github/workflows/airflow-codeql-workflow.yaml" ,
182210 expected : scut.TestReturn {
183211 Score : 7 ,
184212 NumberOfWarn : 1 ,
@@ -196,6 +224,10 @@ func Test_SAST(t *testing.T) {
196224 },
197225 },
198226 searchresult : clients.SearchResponse {},
227+ searchRequest : clients.SearchRequest {
228+ Query : "github/codeql-action/analyze" ,
229+ Path : "/.github/workflows" ,
230+ },
199231 checkRuns : []clients.CheckRun {
200232 {
201233 Status : "completed" ,
@@ -231,6 +263,10 @@ func Test_SAST(t *testing.T) {
231263 },
232264 },
233265 searchresult : clients.SearchResponse {},
266+ searchRequest : clients.SearchRequest {
267+ Query : "github/codeql-action/analyze" ,
268+ Path : "/.github/workflows" ,
269+ },
234270 checkRuns : []clients.CheckRun {
235271 {
236272 Status : "completed" ,
@@ -271,6 +307,10 @@ func Test_SAST(t *testing.T) {
271307 },
272308 },
273309 searchresult : clients.SearchResponse {},
310+ searchRequest : clients.SearchRequest {
311+ Query : "github/codeql-action/analyze" ,
312+ Path : "/.github/workflows" ,
313+ },
274314 checkRuns : []clients.CheckRun {
275315 {
276316 Status : "notCompletedForTestingOnly" ,
@@ -294,12 +334,51 @@ func Test_SAST(t *testing.T) {
294334 NumberOfInfo : 1 ,
295335 },
296336 },
337+ {
338+ name : `KICS workflow with commits` ,
339+ err : nil ,
340+ commits : []clients.Commit {
341+ {
342+ AssociatedMergeRequest : clients.PullRequest {
343+ MergedAt : time .Now ().Add (time .Hour - 1 ),
344+ },
345+ },
346+ {
347+ AssociatedMergeRequest : clients.PullRequest {
348+ MergedAt : time .Now ().Add (time .Hour - 2 ),
349+ },
350+ },
351+ },
352+ searchresult : clients.SearchResponse {},
353+ searchRequest : clients.SearchRequest {
354+ Query : "github/Checkmarx/kics-github-action" ,
355+ Path : "/.github/workflows" ,
356+ },
357+ checkRuns : []clients.CheckRun {
358+ {
359+ Status : "completed" ,
360+ Conclusion : "success" ,
361+ App : clients.CheckRunApp {
362+ Slug : "kics-github-action" ,
363+ },
364+ },
365+ {
366+ Status : "completed" ,
367+ Conclusion : "success" ,
368+ App : clients.CheckRunApp {
369+ Slug : "kics-github-action" ,
370+ },
371+ },
372+ },
373+ path : ".github/workflows/github-kics-workflow.yaml" ,
374+ expected : scut.TestReturn {
375+ Score : checker .MaxResultScore ,
376+ NumberOfDebug : 2 ,
377+ NumberOfInfo : 2 ,
378+ },
379+ },
297380 }
298381 for _ , tt := range tests {
299- searchRequest := clients.SearchRequest {
300- Query : "github/codeql-action/analyze" ,
301- Path : "/.github/workflows" ,
302- }
303382 t .Run (tt .name , func (t * testing.T ) {
304383 t .Parallel ()
305384 ctrl := gomock .NewController (t )
@@ -311,7 +390,7 @@ func Test_SAST(t *testing.T) {
311390 return tt .commits , tt .err
312391 })
313392 mockRepoClient .EXPECT ().ListCheckRunsForRef ("" ).Return (tt .checkRuns , nil ).AnyTimes ()
314- mockRepoClient .EXPECT ().Search (searchRequest ).Return (tt .searchresult , nil ).AnyTimes ()
393+ mockRepoClient .EXPECT ().Search (tt . searchRequest ).Return (tt .searchresult , nil ).AnyTimes ()
315394 mockRepoClient .EXPECT ().ListFiles (gomock .Any ()).DoAndReturn (
316395 func (predicate func (string ) (bool , error )) ([]string , error ) {
317396 if strings .Contains (tt .path , "pom" ) {
0 commit comments