Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI | Fix TotalIssues=-1 when SCS FF is off (AST-63998) #839

Merged
merged 5 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
OrShamirCM marked this conversation as resolved.
Show resolved Hide resolved

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,
},
},
}
}
Loading