diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 1953660db..885b2588c 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -106,6 +106,8 @@ const ( ScsSecretDetectionType = "secret-detection" ScsRepoRequiredMsg = "SCS scan failed to start: Scorecard scan is missing required flags, please include in the ast-cli arguments: " + "--scs-repo-url your_repo_url --scs-repo-token your_repo_token" + ScsRepoWarningMsg = "SCS scan warning: Unable to start Scorecard scan due to missing required flags, please include in the ast-cli arguments: " + + "--scs-repo-url your_repo_url --scs-repo-token your_repo_token" ) var ( @@ -1007,37 +1009,46 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config, hasEnterpr SCSMapConfig[resultsMapValue] = &scsConfig return SCSMapConfig, nil } + + scsSecretDetectionSelected := false + scsScoreCardSelected := false + if SCSEngines != "" { SCSEnginesTypes := strings.Split(SCSEngines, ",") for _, engineType := range SCSEnginesTypes { engineType = strings.TrimSpace(engineType) switch engineType { case ScsSecretDetectionType: - if hasEnterpriseSecretsLicense { - scsConfig.Twoms = trueString - } + scsSecretDetectionSelected = true case ScsScoreCardType: - scsConfig.Scorecard = trueString + scsScoreCardSelected = true } } } else { - scsConfig.Scorecard = trueString - if hasEnterpriseSecretsLicense { - scsConfig.Twoms = trueString - } + scsSecretDetectionSelected = true + scsScoreCardSelected = true } - if scsConfig.Scorecard == trueString { + + if scsSecretDetectionSelected && hasEnterpriseSecretsLicense { + scsConfig.Twoms = trueString + } + if scsScoreCardSelected { if scsRepoToken != "" && scsRepoURL != "" { + scsConfig.Scorecard = trueString scsConfig.RepoToken = scsRepoToken scsConfig.RepoURL = strings.ToLower(scsRepoURL) } else { if userScanTypes == "" { - fmt.Println(ScsRepoRequiredMsg) - return nil, nil + fmt.Println(ScsRepoWarningMsg) + } else { + return nil, errors.Errorf(ScsRepoRequiredMsg) } - return nil, errors.Errorf(ScsRepoRequiredMsg) } } + if scsConfig.Scorecard != trueString && scsConfig.Twoms != trueString { + return nil, nil + } + SCSMapConfig[resultsMapValue] = &scsConfig return SCSMapConfig, nil } diff --git a/internal/commands/scan_test.go b/internal/commands/scan_test.go index 0a56790c0..0659433ae 100644 --- a/internal/commands/scan_test.go +++ b/internal/commands/scan_test.go @@ -931,13 +931,20 @@ func TestCreateScan_WithoutSCSSecretDetection_scsMapNoSecretDetection(t *testing Long: `Scan a project`, } cmdCommand.PersistentFlags().String(commonParams.SCSEnginesFlag, "", "SCS Engine flag") + cmdCommand.PersistentFlags().String(commonParams.SCSRepoTokenFlag, "", "GitHub token to be used with SCS engines") + cmdCommand.PersistentFlags().String(commonParams.SCSRepoURLFlag, "", "GitHub url to be used with SCS engines") _ = cmdCommand.Execute() - _ = cmdCommand.Flags().Set(commonParams.SCSEnginesFlag, "secret-detection") + _ = cmdCommand.Flags().Set(commonParams.SCSEnginesFlag, "secret-detection,scorecard") + _ = cmdCommand.Flags().Set(commonParams.SCSRepoTokenFlag, dummyToken) + _ = cmdCommand.Flags().Set(commonParams.SCSRepoURLFlag, dummyRepo) result, _ := addSCSScan(cmdCommand, resubmitConfig, false) scsConfig := wrappers.SCSConfig{ - Twoms: "", + Twoms: "", + Scorecard: "true", + RepoURL: dummyRepo, + RepoToken: dummyToken, } scsMapConfig := make(map[string]interface{}) scsMapConfig[resultsMapType] = commonParams.MicroEnginesType diff --git a/test/integration/scan_test.go b/test/integration/scan_test.go index 7a03786b1..b01834551 100644 --- a/test/integration/scan_test.go +++ b/test/integration/scan_test.go @@ -1744,7 +1744,7 @@ func TestCreateScan_WithTypeScs_Success(t *testing.T) { executeCmdWithTimeOutNilAssertion(t, "SCS scan must complete successfully", 4*time.Minute, args...) } -func TestCreateScan_WithNoScanTypesFlag_SuccessAndScsNotScanned(t *testing.T) { +func TestCreateScan_WithNoScanTypesAndScsFlagsNotPresent_SuccessAndScsScanned(t *testing.T) { _, projectName := getRootProject(t) args := []string{ @@ -1752,11 +1752,10 @@ func TestCreateScan_WithNoScanTypesFlag_SuccessAndScsNotScanned(t *testing.T) { flag(params.ProjectName), projectName, flag(params.SourcesFlag), Zip, flag(params.BranchFlag), "main", - flag(params.SCSRepoTokenFlag), scsRepoToken, } - output := executeCmdWithTimeOutNilAssertion(t, "Scan must complete successfully if no scan-types specified, even if missing scs-repo flags", timeout, args...) - assert.Assert(t, !strings.Contains(output.String(), params.ScsType), "Scs scan must not run if all required flags are not provided") + output := executeCmdWithTimeOutNilAssertion(t, "Scan must complete successfully if no scan-types specified and with missing scs-repo flags", timeout, args...) + assert.Assert(t, strings.Contains(output.String(), params.ScsType), "SCS scan should run") } func TestCreateScan_WithNoScanTypesFlagButScsFlagsPresent_SuccessAndScsScanned(t *testing.T) {