Skip to content

Commit

Permalink
CLI | Fix TotalIssues=-1 when SCS FF is off (AST-63998) (#839)
Browse files Browse the repository at this point in the history
* fix -1 total issues when scs FF is off

* added unit test

* fix lint

* fix errors

---------

Co-authored-by: AlvoBen <alvo@post.bgu.ac.il>
  • Loading branch information
AlvoBen and BenAlvo1 committed Aug 26, 2024
1 parent b795f72 commit 6227118
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 4 deletions.
7 changes: 4 additions & 3 deletions internal/commands/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ func enhanceWithScanSummary(summary *wrappers.ResultSummary, results *wrappers.S
}
}

summary.TotalIssues = summary.SastIssues + summary.ScaIssues + summary.KicsIssues + summary.GetAPISecurityDocumentationTotal()

if summary.HasSCS() && wrappers.IsSCSEnabled {
summary.EnginesResult[commonParams.ScsType].Info = summary.SCSOverview.RiskSummary[infoLabel]
summary.EnginesResult[commonParams.ScsType].Low = summary.SCSOverview.RiskSummary[lowLabel]
Expand All @@ -705,8 +707,8 @@ func enhanceWithScanSummary(summary *wrappers.ResultSummary, results *wrappers.S
if !criticalEnabled {
summary.EnginesResult[commonParams.ScsType].Critical = notAvailableNumber
}
summary.TotalIssues += summary.ScsIssues
}
summary.TotalIssues = summary.SastIssues + summary.ScaIssues + summary.KicsIssues + summary.GetAPISecurityDocumentationTotal()
if wrappers.IsContainersEnabled {
if *summary.ContainersIssues >= 0 {
summary.TotalIssues += *summary.ContainersIssues
Expand Down Expand Up @@ -881,9 +883,8 @@ func printResultsSummaryTable(summary *wrappers.ResultSummary) {
totalLowIssues := summary.EnginesResult.GetLowIssues()
totalInfoIssues := summary.EnginesResult.GetInfoIssues()

totalIssues := summary.TotalIssues + summary.ScsIssues
fmt.Printf(tableLine + twoNewLines)
fmt.Printf(" Total Results: %d \n", totalIssues)
fmt.Printf(" Total Results: %d \n", summary.TotalIssues)
fmt.Println(tableLine)
fmt.Printf(TableTitleFormat, " ", "Critical", "High", "Medium", "Low", "Info", "Status")

Expand Down
89 changes: 88 additions & 1 deletion internal/commands/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/checkmarx/ast-cli/internal/commands/util/printer"
errorConstants "github.com/checkmarx/ast-cli/internal/constants/errors"
"github.com/checkmarx/ast-cli/internal/params"
params "github.com/checkmarx/ast-cli/internal/params"
"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/checkmarx/ast-cli/internal/wrappers/mock"
"gotest.tools/assert"
Expand Down Expand Up @@ -973,3 +973,90 @@ func TestGetResultsSummaryConsoleFormatWithCriticalDisabled(t *testing.T) {

mock.SetScsMockVarsToDefault()
}

func Test_enhanceWithScanSummary(t *testing.T) {
tests := []struct {
name string
summary *wrappers.ResultSummary
results *wrappers.ScanResultsCollection
featureFlagsWrapper wrappers.FeatureFlagsWrapper
expectedIssues int
}{
{
name: "scan summary with no vulnerabilities",
summary: createEmptyResultSummary(),
results: &wrappers.ScanResultsCollection{
Results: nil,
TotalCount: 0,
ScanID: "MOCK",
},
featureFlagsWrapper: mock.FeatureFlagsMockWrapper{},
expectedIssues: 0,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
enhanceWithScanSummary(tt.summary, tt.results, tt.featureFlagsWrapper)
assert.Equal(t, tt.expectedIssues, tt.summary.TotalIssues)
})
}
}

func createEmptyResultSummary() *wrappers.ResultSummary {
return &wrappers.ResultSummary{
TotalIssues: 0,
CriticalIssues: 0,
HighIssues: 0,
MediumIssues: 0,
LowIssues: 0,
InfoIssues: 0,
SastIssues: 0,
ScaIssues: 0,
KicsIssues: 0,
ScsIssues: 0,
SCSOverview: wrappers.SCSOverview{},
APISecurity: wrappers.APISecResult{
APICount: 0,
TotalRisksCount: 0,
Risks: []int{0, 0, 0, 0},
StatusCode: 0,
},
EnginesEnabled: []string{"sast", "sca", "kics", "containers"},
EnginesResult: wrappers.EnginesResultsSummary{
params.SastType: &wrappers.EngineResultSummary{
Critical: 0,
High: 0,
Medium: 0,
Low: 0,
Info: 0,
},
params.ScaType: &wrappers.EngineResultSummary{
Critical: 0,
High: 0,
Medium: 0,
Low: 0,
Info: 0,
},
params.KicsType: &wrappers.EngineResultSummary{
Critical: 0,
High: 0,
Medium: 0,
Low: 0,
Info: 0,
},
params.APISecType: &wrappers.EngineResultSummary{
Critical: 0,
High: 0,
Medium: 0,
Low: 0,
},
params.ContainersType: &wrappers.EngineResultSummary{
Critical: 0,
High: 0,
Medium: 0,
Low: 0,
},
},
}
}

0 comments on commit 6227118

Please sign in to comment.