From dade2e477246f8f04d92b745b8bff45fb4f7d50d Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 20 Aug 2024 10:35:45 +0300 Subject: [PATCH 1/4] fix -1 total issues when scs FF is off --- internal/commands/result.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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") From cc90033b509bd9fa3425c8956171e97e20ea0a9e Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 20 Aug 2024 18:10:43 +0300 Subject: [PATCH 2/4] added unit test --- internal/commands/result_test.go | 87 ++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/internal/commands/result_test.go b/internal/commands/result_test.go index bd63d8870..ccf4cd89c 100644 --- a/internal/commands/result_test.go +++ b/internal/commands/result_test.go @@ -13,6 +13,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" + commonParams "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 +974,89 @@ 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 { + 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{ + Sast: &wrappers.EngineResultSummary{ + Critical: 0, + High: 0, + Medium: 0, + Low: 0, + Info: 0, + }, + commonParams.ScaType: &wrappers.EngineResultSummary{ + Critical: 0, + High: 0, + Medium: 0, + Low: 0, + Info: 0, + }, + commonParams.KicsType: &wrappers.EngineResultSummary{ + Critical: 0, + High: 0, + Medium: 0, + Low: 0, + Info: 0, + }, + commonParams.APISecType: &wrappers.EngineResultSummary{ + Critical: 0, + High: 0, + Medium: 0, + Low: 0, + }, + commonParams.ContainersType: &wrappers.EngineResultSummary{ + Critical: 0, + High: 0, + Medium: 0, + Low: 0, + }, + }, + } +} From d3526219849ada7f020e908b2384163656e670fd Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 20 Aug 2024 18:16:19 +0300 Subject: [PATCH 3/4] fix lint --- internal/commands/result_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/commands/result_test.go b/internal/commands/result_test.go index ccf4cd89c..edac9445d 100644 --- a/internal/commands/result_test.go +++ b/internal/commands/result_test.go @@ -13,7 +13,6 @@ 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" - commonParams "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" @@ -996,6 +995,7 @@ func Test_enhanceWithScanSummary(t *testing.T) { }, } 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) @@ -1031,27 +1031,27 @@ func createEmptyResultSummary() *wrappers.ResultSummary { Low: 0, Info: 0, }, - commonParams.ScaType: &wrappers.EngineResultSummary{ + ScaType: &wrappers.EngineResultSummary{ Critical: 0, High: 0, Medium: 0, Low: 0, Info: 0, }, - commonParams.KicsType: &wrappers.EngineResultSummary{ + KicsType: &wrappers.EngineResultSummary{ Critical: 0, High: 0, Medium: 0, Low: 0, Info: 0, }, - commonParams.APISecType: &wrappers.EngineResultSummary{ + APISecType: &wrappers.EngineResultSummary{ Critical: 0, High: 0, Medium: 0, Low: 0, }, - commonParams.ContainersType: &wrappers.EngineResultSummary{ + ContainersType: &wrappers.EngineResultSummary{ Critical: 0, High: 0, Medium: 0, From a627ca775c6f05c02057fa22ced337643594dc33 Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Wed, 21 Aug 2024 10:36:07 +0300 Subject: [PATCH 4/4] fix errors --- internal/commands/result_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/commands/result_test.go b/internal/commands/result_test.go index edac9445d..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" @@ -1024,34 +1024,34 @@ func createEmptyResultSummary() *wrappers.ResultSummary { }, EnginesEnabled: []string{"sast", "sca", "kics", "containers"}, EnginesResult: wrappers.EnginesResultsSummary{ - Sast: &wrappers.EngineResultSummary{ + params.SastType: &wrappers.EngineResultSummary{ Critical: 0, High: 0, Medium: 0, Low: 0, Info: 0, }, - ScaType: &wrappers.EngineResultSummary{ + params.ScaType: &wrappers.EngineResultSummary{ Critical: 0, High: 0, Medium: 0, Low: 0, Info: 0, }, - KicsType: &wrappers.EngineResultSummary{ + params.KicsType: &wrappers.EngineResultSummary{ Critical: 0, High: 0, Medium: 0, Low: 0, Info: 0, }, - APISecType: &wrappers.EngineResultSummary{ + params.APISecType: &wrappers.EngineResultSummary{ Critical: 0, High: 0, Medium: 0, Low: 0, }, - ContainersType: &wrappers.EngineResultSummary{ + params.ContainersType: &wrappers.EngineResultSummary{ Critical: 0, High: 0, Medium: 0,