Skip to content

Commit

Permalink
Add test with positive outcome
Browse files Browse the repository at this point in the history
Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
DavidKorczynski committed Dec 12, 2023
1 parent 08012f4 commit e870f9f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
13 changes: 6 additions & 7 deletions checks/evaluation/sast.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func SAST(name string,
// retun checker.InconclusiveResultScore.
return checker.CreateRuntimeErrorResult(name, sce.ErrScorecardInternal)
}
// Sast inconclusive.
if snykScore != checker.InconclusiveResultScore {
if snykScore == checker.MaxResultScore {
return checker.CreateMaxScoreResult(name, "SAST tool detected: Snyk")
}
}

// Both scores are conclusive.
// We assume the CodeQl config uses a cron and is not enabled as pre-submit.
Expand Down Expand Up @@ -106,13 +112,6 @@ func SAST(name string,
}
}

// Sast inconclusive.
if snykScore != checker.InconclusiveResultScore {
if snykScore == checker.MaxResultScore {
return checker.CreateMaxScoreResult(name, "SAST tool detected: Snyk")
}
}

if codeQlScore != checker.InconclusiveResultScore {
if codeQlScore == checker.MaxResultScore {
return checker.CreateMaxScoreResult(name, "SAST tool detected: CodeQL")
Expand Down
30 changes: 30 additions & 0 deletions checks/evaluation/sast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,36 @@ func TestSAST(t *testing.T) {
NumberOfInfo: 0,
},
},
{
name: "Snyk is installed, Sonar and CodeQL are not installed",
findings: []finding.Finding{
{
Probe: "sastToolCodeQLInstalled",
Outcome: finding.OutcomeNegative,
},
{
Probe: "sastToolSnykInstalled",
Outcome: finding.OutcomePositive,
},
{
Probe: "sastToolRunsOnAllCommits",
Outcome: finding.OutcomePositive,
Values: map[string]int{
"totalPullRequestsAnalyzed": 1,
"totalPullRequestsMerged": 3,
},
},
{
Probe: "sastToolSonarInstalled",
Outcome: finding.OutcomeNegative,
},
},
result: scut.TestReturn{
Score: 10,
NumberOfWarn: 1,
NumberOfInfo: 2,
},
},
}
for _, tt := range tests {
tt := tt
Expand Down

0 comments on commit e870f9f

Please sign in to comment.