Skip to content

Commit

Permalink
MC-397-Adding FF to show/hide the SCS from console summary (#789)
Browse files Browse the repository at this point in the history
* Adding FF to show/hide the SCS from console summary

* Updated setIsSCSEnabled and unit tests

* Added clearFlags() on SCS unit tests

* Update go version

* Corrected usage of scsEngineCLIEnabled

---------

Co-authored-by: tamarleviCm <110327792+tamarleviCm@users.noreply.github.com>
  • Loading branch information
diogo-fjrocha and tamarleviCm authored Jul 3, 2024
1 parent 3ab7a8a commit 40cfc67
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/checkmarx/ast-cli

go 1.22.4
go 1.22.5

require (
github.com/CheckmarxDev/containers-resolver v1.0.6
Expand Down
17 changes: 13 additions & 4 deletions internal/commands/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func summaryReport(
summary.APISecurity = *apiSecRisks
}

if summary.HasSCS() {
if summary.HasSCS() && wrappers.IsSCSEnabled {
SCSOverview, err := getScanOverviewForSCSScanner(scsScanOverviewWrapper, summary.ScanID)
if err != nil {
return nil, err
Expand Down Expand Up @@ -674,7 +674,7 @@ func enhanceWithScanSummary(summary *wrappers.ResultSummary, results *wrappers.S
summary.EnginesResult[commonParams.APISecType].High = summary.APISecurity.Risks[1]
}

if summary.HasSCS() {
if summary.HasSCS() && wrappers.IsSCSEnabled {
summary.EnginesResult[commonParams.ScsType].Info = summary.SCSOverview.RiskSummary[infoLabel]
summary.EnginesResult[commonParams.ScsType].Low = summary.SCSOverview.RiskSummary[lowLabel]
summary.EnginesResult[commonParams.ScsType].Medium = summary.SCSOverview.RiskSummary[mediumLabel]
Expand Down Expand Up @@ -749,7 +749,7 @@ func writeConsoleSummary(summary *wrappers.ResultSummary) error {
printAPIsSecuritySummary(summary)
}

if summary.HasSCS() {
if summary.HasSCS() && wrappers.IsSCSEnabled {
printSCSSummary(summary.SCSOverview.MicroEngineOverviews)
}

Expand Down Expand Up @@ -846,7 +846,9 @@ func printResultsSummaryTable(summary *wrappers.ResultSummary) {
printTableRow("IAC", summary.EnginesResult[commonParams.KicsType], summary.EnginesResult[commonParams.KicsType].StatusCode)
printTableRow("SAST", summary.EnginesResult[commonParams.SastType], summary.EnginesResult[commonParams.SastType].StatusCode)
printTableRow("SCA", summary.EnginesResult[commonParams.ScaType], summary.EnginesResult[commonParams.ScaType].StatusCode)
printTableRow("SCS", summary.EnginesResult[commonParams.ScsType], summary.EnginesResult[commonParams.ScsType].StatusCode)
if wrappers.IsSCSEnabled {
printTableRow("SCS", summary.EnginesResult[commonParams.ScsType], summary.EnginesResult[commonParams.ScsType].StatusCode)
}
if wrappers.IsContainersEnabled {
printTableRow("CONTAINERS", summary.EnginesResult[commonParams.ContainersType], summary.EnginesResult[commonParams.ContainersType].StatusCode)
}
Expand Down Expand Up @@ -983,6 +985,12 @@ func runGetCodeBashingCommand(
return nil
}
}

func setIsSCSEnabled(featureFlagsWrapper wrappers.FeatureFlagsWrapper) {
scsEngineCLIEnabled, _ := wrappers.GetSpecificFeatureFlag(featureFlagsWrapper, wrappers.SCSEngineCLIEnabled)
wrappers.IsSCSEnabled = scsEngineCLIEnabled.Status
}

func setIsContainersEnabled(agent string, featureFlagsWrapper wrappers.FeatureFlagsWrapper) {
agentSupported := !containsIgnoreCase(containerEngineUnsupportedAgents, agent)
containerEngineCLIEnabled, _ := wrappers.GetSpecificFeatureFlag(featureFlagsWrapper, wrappers.ContainerEngineCLIEnabled)
Expand Down Expand Up @@ -1010,6 +1018,7 @@ func CreateScanReport(
) error {
reportList := strings.Split(reportTypes, ",")
results := &wrappers.ScanResultsCollection{}
setIsSCSEnabled(featureFlagsWrapper)
setIsContainersEnabled(agent, featureFlagsWrapper)
summary, err := convertScanToResultsSummary(scan, resultsWrapper)
if err != nil {
Expand Down
37 changes: 35 additions & 2 deletions internal/commands/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,11 @@ func TestRunGetResultsByScanIdGLScaFormat_NoVulnerabilities_Success(t *testing.T
}

func TestRunGetResultsByScanIdSummaryConsoleFormat_ScsNotScanned_ScsMissingInReport(t *testing.T) {
clearFlags()
mock.HasScs = false
mock.ScsScanPartial = false
mock.ScorecardScanned = false
mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.SCSEngineCLIEnabled, Status: true}

buffer, err := executeRedirectedOsStdoutTestCommand(createASTTestCommand(),
"results", "show", "--scan-id", "MOCK", "--report-format", "summaryConsole")
Expand All @@ -839,9 +841,11 @@ func TestRunGetResultsByScanIdSummaryConsoleFormat_ScsNotScanned_ScsMissingInRep
}

func TestRunGetResultsByScanIdSummaryConsoleFormat_ScsPartial_ScsPartialInReport(t *testing.T) {
clearFlags()
mock.HasScs = true
mock.ScsScanPartial = true
mock.ScorecardScanned = true
mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.SCSEngineCLIEnabled, Status: true}

buffer, err := executeRedirectedOsStdoutTestCommand(createASTTestCommand(),
"results", "show", "--scan-id", "MOCK", "--report-format", "summaryConsole")
Expand All @@ -852,10 +856,10 @@ func TestRunGetResultsByScanIdSummaryConsoleFormat_ScsPartial_ScsPartialInReport
cleanString := ansiRegexp.ReplaceAllString(stdoutString, "")
fmt.Print(stdoutString)

TotalResults := "Total Results: 17"
TotalResults := "Total Results: 18"
assert.Equal(t, strings.Contains(cleanString, TotalResults), true,
"Expected: "+TotalResults)
TotalSummary := "| TOTAL 10 4 3 0 Completed |"
TotalSummary := "| TOTAL 10 5 3 0 Completed |"
assert.Equal(t, strings.Contains(cleanString, TotalSummary), true,
"Expected TOTAL summary: "+TotalSummary)
scsSummary := "| SCS 5 3 2 0 Partial |"
Expand All @@ -872,9 +876,11 @@ func TestRunGetResultsByScanIdSummaryConsoleFormat_ScsPartial_ScsPartialInReport
}

func TestRunGetResultsByScanIdSummaryConsoleFormat_ScsScorecardNotScanned_ScorecardMissingInReport(t *testing.T) {
clearFlags()
mock.HasScs = true
mock.ScsScanPartial = false
mock.ScorecardScanned = false
mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.SCSEngineCLIEnabled, Status: true}

buffer, err := executeRedirectedOsStdoutTestCommand(createASTTestCommand(),
"results", "show", "--scan-id", "MOCK", "--report-format", "summaryConsole")
Expand All @@ -895,3 +901,30 @@ func TestRunGetResultsByScanIdSummaryConsoleFormat_ScsScorecardNotScanned_Scorec

mock.SetScsMockVarsToDefault()
}

func TestRunGetResultsByScanIdSummaryConsoleFormat_SCSFlagNotEnabled_SCSMissingInReport(t *testing.T) {
clearFlags()
mock.HasScs = true
mock.ScsScanPartial = false
mock.ScorecardScanned = true
mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.SCSEngineCLIEnabled, Status: false}

buffer, err := executeRedirectedOsStdoutTestCommand(createASTTestCommand(),
"results", "show", "--scan-id", "MOCK", "--report-format", "summaryConsole")
assert.NilError(t, err)

stdoutString := buffer.String()
fmt.Print(stdoutString)

scsSummary := "| SCS"
assert.Equal(t, !strings.Contains(stdoutString, scsSummary), true,
"Expected SCS summary:"+scsSummary)
secretDetectionSummary := "Secret Detection"
assert.Equal(t, !strings.Contains(stdoutString, secretDetectionSummary), true,
"Expected Secret Detection summary to be missing:"+secretDetectionSummary)
scorecardSummary := "Scorecard"
assert.Equal(t, !strings.Contains(stdoutString, scorecardSummary), true,
"Expected Scorecard summary to be missing:"+scorecardSummary)

mock.SetScsMockVarsToDefault()
}
1 change: 1 addition & 0 deletions internal/wrappers/feature-flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const tenantIDClaimKey = "tenant_id"
const PackageEnforcementEnabled = "PACKAGE_ENFORCEMENT_ENABLED"
const MinioEnabled = "MINIO_ENABLED"
const ContainerEngineCLIEnabled = "CONTAINER_ENGINE_CLI_ENABLED"
const SCSEngineCLIEnabled = "NEW_2MS_SCORECARD_RESULTS_CLI_ENABLED"
const NewScanReportEnabled = "NEW_SAST_SCAN_REPORT_ENABLED"
const maxRetries = 3

Expand Down
2 changes: 2 additions & 0 deletions internal/wrappers/results-summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type EngineResultSummary struct {

type EnginesResultsSummary map[string]*EngineResultSummary

var IsSCSEnabled bool

var IsContainersEnabled bool

func (engineSummary *EnginesResultsSummary) GetHighIssues() int {
Expand Down

0 comments on commit 40cfc67

Please sign in to comment.