diff --git a/internal/commands/result.go b/internal/commands/result.go index 8a24c26b2..6140f3cb8 100644 --- a/internal/commands/result.go +++ b/internal/commands/result.go @@ -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] @@ -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 @@ -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") diff --git a/internal/commands/result_test.go b/internal/commands/result_test.go index bd63d8870..4a7e4ed2e 100644 --- a/internal/commands/result_test.go +++ b/internal/commands/result_test.go @@ -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" @@ -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, + }, + }, + } +}