diff --git a/internal/commands/scan.go b/internal/commands/scan.go index f3b7b098a..464549c49 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -522,6 +522,12 @@ func scanCreateSubCommand( []string{}, commonParams.KicsPlatformsFlagUsage, ) + createScanCmd.PersistentFlags().Bool( + commonParams.SastFastScanFlag, + false, + "Enable SAST Fast Scan configuration", + ) + createScanCmd.PersistentFlags().StringSlice( commonParams.IacsPlatformsFlag, []string{}, @@ -933,7 +939,9 @@ func addSastScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) map[strin sastConfig := wrappers.SastConfig{} sastMapConfig[resultsMapType] = commonParams.SastType incrementalVal, _ := cmd.Flags().GetBool(commonParams.IncrementalSast) + fastScan, _ := cmd.Flags().GetBool(commonParams.SastFastScanFlag) sastConfig.Incremental = strconv.FormatBool(incrementalVal) + sastConfig.FastScanMode = strconv.FormatBool(fastScan) sastConfig.PresetName, _ = cmd.Flags().GetString(commonParams.PresetName) sastConfig.Filter, _ = cmd.Flags().GetString(commonParams.SastFilterFlag) for _, config := range resubmitConfig { diff --git a/internal/commands/scan_test.go b/internal/commands/scan_test.go index 658661460..da25cc89f 100644 --- a/internal/commands/scan_test.go +++ b/internal/commands/scan_test.go @@ -555,6 +555,54 @@ func TestAddScaScan(t *testing.T) { } } +func TestAddSastScan_WithFastScanFlag_ShouldPass(t *testing.T) { + var resubmitConfig []wrappers.Config + + cmdCommand := &cobra.Command{ + Use: "scan", + Short: "Scan a project", + Long: `Scan a project with SAST fast scan configuration`, + } + + cmdCommand.PersistentFlags().String(commonParams.PresetName, "", "Preset name") + cmdCommand.PersistentFlags().String(commonParams.SastFilterFlag, "", "Filter for SAST scan") + cmdCommand.PersistentFlags().Bool(commonParams.IncrementalSast, false, "Incremental SAST scan") + cmdCommand.PersistentFlags().Bool(commonParams.SastFastScanFlag, false, "Enable SAST Fast Scan") + + _ = cmdCommand.Execute() + + _ = cmdCommand.Flags().Set(commonParams.PresetName, "test") + _ = cmdCommand.Flags().Set(commonParams.SastFilterFlag, "test") + _ = cmdCommand.Flags().Set(commonParams.IncrementalSast, "true") + _ = cmdCommand.Flags().Set(commonParams.SastFastScanFlag, "true") + + result := addSastScan(cmdCommand, resubmitConfig) + + sastConfig := wrappers.SastConfig{ + PresetName: "test", + Filter: "test", + Incremental: "true", + FastScanMode: "true", + } + sastMapConfig := make(map[string]interface{}) + sastMapConfig[resultsMapType] = commonParams.SastType + sastMapConfig[resultsMapValue] = &sastConfig + + if !reflect.DeepEqual(result, sastMapConfig) { + t.Errorf("Expected %+v, but got %+v", sastMapConfig, result) + } +} + +func TestCreateScanWithFastScanFlagIncorrectCase(t *testing.T) { + baseArgs := []string{"scan", "create", "--project-name", "MOCK", "--branch", "b", "--scan-types", "sast", "--file-source", "."} + + err := execCmdNotNilAssertion(t, append(baseArgs, "--SAST-FAST-SCAN", "true")...) + assert.ErrorContains(t, err, "unknown flag: --SAST-FAST-SCAN", err.Error()) + + err = execCmdNotNilAssertion(t, append(baseArgs, "--Sast-Fast-Scan", "true")...) + assert.ErrorContains(t, err, "unknown flag: --Sast-Fast-Scan", err.Error()) +} + func TestAddSastScan(t *testing.T) { var resubmitConfig []wrappers.Config @@ -567,6 +615,7 @@ func TestAddSastScan(t *testing.T) { cmdCommand.PersistentFlags().String(commonParams.PresetName, "", "Preset name") cmdCommand.PersistentFlags().String(commonParams.SastFilterFlag, "", "Filter for SAST scan") cmdCommand.PersistentFlags().Bool(commonParams.IncrementalSast, false, "Incremental SAST scan") + cmdCommand.PersistentFlags().Bool(commonParams.SastFastScanFlag, true, "Enable SAST Fast Scan") _ = cmdCommand.Execute() @@ -577,9 +626,10 @@ func TestAddSastScan(t *testing.T) { result := addSastScan(cmdCommand, resubmitConfig) sastConfig := wrappers.SastConfig{ - PresetName: "test", - Filter: "test", - Incremental: "true", + PresetName: "test", + Filter: "test", + Incremental: "true", + FastScanMode: "true", } sastMapConfig := make(map[string]interface{}) sastMapConfig[resultsMapType] = commonParams.SastType diff --git a/internal/params/flags.go b/internal/params/flags.go index 8efeeb7d3..ddf5fc9f5 100644 --- a/internal/params/flags.go +++ b/internal/params/flags.go @@ -56,6 +56,7 @@ const ( TimeoutFlag = "timeout" TimeoutFlagUsage = "Timeout for network activity, (default 5 seconds)" NtlmProxyDomainFlag = "proxy-ntlm-domain" + SastFastScanFlag = "sast-fast-scan" NtlmProxyDomainFlagUsage = "Window domain when using NTLM proxy" BaseURIFlagUsage = "The base system URI" BaseAuthURIFlag = "base-auth-uri" diff --git a/internal/wrappers/scans.go b/internal/wrappers/scans.go index dd8a41119..981a2784a 100644 --- a/internal/wrappers/scans.go +++ b/internal/wrappers/scans.go @@ -126,6 +126,7 @@ type SastConfig struct { EngineVerbose string `json:"engineVerbose,omitempty"` LanguageMode string `json:"languageMode,omitempty"` PresetName string `json:"presetName,omitempty"` + FastScanMode string `json:"fastScanMode,omitempty"` } type KicsConfig struct { diff --git a/test/integration/scan_test.go b/test/integration/scan_test.go index c8b6055de..67cec7b1b 100644 --- a/test/integration/scan_test.go +++ b/test/integration/scan_test.go @@ -126,6 +126,19 @@ func TestScansE2E(t *testing.T) { assert.Equal(t, len(glob), 0, "Zip file not removed") } +func TestFastScan(t *testing.T) { + projectName := getProjectNameForScanTests() + // Create a scan + scanID, projectID := createScanWithFastScan(t, Dir, projectName, map[string]string{}) + defer deleteProject(t, projectID) + executeScanAssertions(t, projectID, scanID, map[string]string{}) +} + +func createScanWithFastScan(t *testing.T, source string, name string, tags map[string]string) (string, string) { + args := append(getCreateArgsWithName(source, tags, name, "sast"), flag(params.SastFastScanFlag)) + return executeCreateScan(t, args) +} + func TestScansUpdateProjectGroups(t *testing.T) { scanID, projectID := executeCreateScan(t, getCreateArgs(Zip, Tags, "sast")) response := listScanByID(t, scanID)