Skip to content

Commit d40a152

Browse files
merge with main
2 parents 03b3c32 + 3c38fb2 commit d40a152

File tree

5 files changed

+185
-40
lines changed

5 files changed

+185
-40
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,5 @@ jobs:
146146
cli_release_version: ""
147147
release_author: "Phoenix Team"
148148
release_url: https://github.com/Checkmarx/ast-cli/releases/tag/${{ inputs.tag }}
149-
jira_product_name: ASTCLI_${{ inputs.tag }}
149+
jira_product_name: ASTCLI
150150
secrets: inherit

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM cgr.dev/chainguard/bash@sha256:1abc09ac352efdc60d855bd159b9b66df6596a174400752ae3c537b5350779a9
1+
FROM checkmarx/bash:5.2.37-r2
22
USER nonroot
33

44
COPY cx /app/bin/cx

internal/commands/scan.go

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const (
8686
configFilterKey = "filter"
8787
configFilterPlatforms = "platforms"
8888
configIncremental = "incremental"
89+
configFastScan = "fastScanMode"
8990
configPresetName = "presetName"
9091
configEngineVerbose = "engineVerbose"
9192
configLanguageMode = "languageMode"
@@ -818,45 +819,66 @@ func getResubmitConfiguration(scansWrapper wrappers.ScansWrapper, projectID, use
818819
}
819820

820821
func addSastScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) map[string]interface{} {
821-
if scanTypeEnabled(commonParams.SastType) {
822-
sastMapConfig := make(map[string]interface{})
823-
sastConfig := wrappers.SastConfig{}
824-
sastMapConfig[resultsMapType] = commonParams.SastType
825-
incrementalVal, _ := cmd.Flags().GetBool(commonParams.IncrementalSast)
822+
// Check if SAST is enabled
823+
if !scanTypeEnabled(commonParams.SastType) {
824+
return nil
825+
}
826+
827+
sastMapConfig := make(map[string]interface{})
828+
sastConfig := wrappers.SastConfig{}
829+
sastMapConfig[resultsMapType] = commonParams.SastType
830+
831+
sastFastScanChanged := cmd.Flags().Changed(commonParams.SastFastScanFlag)
832+
sastIncrementalChanged := cmd.Flags().Changed(commonParams.IncrementalSast)
833+
834+
if sastFastScanChanged {
826835
fastScan, _ := cmd.Flags().GetBool(commonParams.SastFastScanFlag)
827-
sastConfig.Incremental = strconv.FormatBool(incrementalVal)
828836
sastConfig.FastScanMode = strconv.FormatBool(fastScan)
829-
sastConfig.PresetName, _ = cmd.Flags().GetString(commonParams.PresetName)
830-
sastConfig.Filter, _ = cmd.Flags().GetString(commonParams.SastFilterFlag)
831-
for _, config := range resubmitConfig {
832-
if config.Type != commonParams.SastType {
833-
continue
834-
}
835-
resubmitIncremental := config.Value[configIncremental]
836-
if resubmitIncremental != nil && !incrementalVal {
837-
sastConfig.Incremental = resubmitIncremental.(string)
838-
}
839-
resubmitPreset := config.Value[configPresetName]
840-
if resubmitPreset != nil && sastConfig.PresetName == "" {
841-
sastConfig.PresetName = resubmitPreset.(string)
842-
}
843-
resubmitFilter := config.Value[configFilterKey]
844-
if resubmitFilter != nil && sastConfig.Filter == "" {
845-
sastConfig.Filter = resubmitFilter.(string)
846-
}
847-
resubmitEngineVerbose := config.Value[configEngineVerbose]
848-
if resubmitEngineVerbose != nil {
849-
sastConfig.EngineVerbose = resubmitEngineVerbose.(string)
850-
}
851-
resubmitLanguageMode := config.Value[configLanguageMode]
852-
if resubmitLanguageMode != nil {
853-
sastConfig.LanguageMode = resubmitLanguageMode.(string)
854-
}
837+
}
838+
839+
if sastIncrementalChanged {
840+
incrementalVal, _ := cmd.Flags().GetBool(commonParams.IncrementalSast)
841+
sastConfig.Incremental = strconv.FormatBool(incrementalVal)
842+
}
843+
844+
sastConfig.PresetName, _ = cmd.Flags().GetString(commonParams.PresetName)
845+
sastConfig.Filter, _ = cmd.Flags().GetString(commonParams.SastFilterFlag)
846+
847+
for _, config := range resubmitConfig {
848+
if config.Type != commonParams.SastType {
849+
continue
855850
}
856-
sastMapConfig[resultsMapValue] = &sastConfig
857-
return sastMapConfig
851+
852+
overrideSastConfigValue(sastFastScanChanged, sastIncrementalChanged, &sastConfig, config)
853+
}
854+
855+
sastMapConfig[resultsMapValue] = &sastConfig
856+
return sastMapConfig
857+
}
858+
859+
func overrideSastConfigValue(sastFastScanChanged, sastIncrementalChanged bool, sastConfig *wrappers.SastConfig, config wrappers.Config) {
860+
setIfEmpty := func(configValue *string, resubmitValue interface{}) {
861+
if *configValue == "" && resubmitValue != nil {
862+
*configValue = resubmitValue.(string)
863+
}
864+
}
865+
866+
if resubmitIncremental := config.Value[configIncremental]; resubmitIncremental != nil && !sastIncrementalChanged {
867+
sastConfig.Incremental = resubmitIncremental.(string)
868+
}
869+
if resubmitFastScan := config.Value[configFastScan]; resubmitFastScan != nil && !sastFastScanChanged {
870+
sastConfig.FastScanMode = resubmitFastScan.(string)
871+
}
872+
873+
setIfEmpty(&sastConfig.PresetName, config.Value[configPresetName])
874+
setIfEmpty(&sastConfig.Filter, config.Value[configFilterKey])
875+
876+
if resubmitEngineVerbose := config.Value[configEngineVerbose]; resubmitEngineVerbose != nil {
877+
sastConfig.EngineVerbose = resubmitEngineVerbose.(string)
878+
}
879+
if resubmitLanguageMode := config.Value[configLanguageMode]; resubmitLanguageMode != nil {
880+
sastConfig.LanguageMode = resubmitLanguageMode.(string)
858881
}
859-
return nil
860882
}
861883

862884
func addKicsScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) map[string]interface{} {

internal/commands/scan_test.go

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ func TestAddSastScan(t *testing.T) {
869869
cmdCommand.PersistentFlags().String(commonParams.PresetName, "", "Preset name")
870870
cmdCommand.PersistentFlags().String(commonParams.SastFilterFlag, "", "Filter for SAST scan")
871871
cmdCommand.PersistentFlags().Bool(commonParams.IncrementalSast, false, "Incremental SAST scan")
872-
cmdCommand.PersistentFlags().Bool(commonParams.SastFastScanFlag, true, "Enable SAST Fast Scan")
872+
cmdCommand.PersistentFlags().Bool(commonParams.SastFastScanFlag, false, "Enable SAST Fast Scan")
873873

874874
_ = cmdCommand.Execute()
875875

@@ -883,7 +883,7 @@ func TestAddSastScan(t *testing.T) {
883883
PresetName: "test",
884884
Filter: "test",
885885
Incremental: "true",
886-
FastScanMode: "true",
886+
FastScanMode: "",
887887
}
888888
sastMapConfig := make(map[string]interface{})
889889
sastMapConfig[resultsMapType] = commonParams.SastType
@@ -1766,6 +1766,129 @@ func TestUploadZip_whenUserNotProvideZip_shouldReturnZipFilePathInFailureCase(t
17661766
assert.Equal(t, zipPath, "failureCase.zip")
17671767
}
17681768

1769+
func TestAddSastScan_ScanFlags(t *testing.T) {
1770+
var resubmitConfig []wrappers.Config
1771+
1772+
tests := []struct {
1773+
name string
1774+
requiredIncrementalSet bool
1775+
requiredFastScanSet bool
1776+
fastScanFlag string
1777+
incrementalFlag string
1778+
expectedConfig wrappers.SastConfig
1779+
}{
1780+
{
1781+
name: "Fast scan and Incremental scan both false",
1782+
requiredIncrementalSet: true,
1783+
requiredFastScanSet: true,
1784+
fastScanFlag: "false",
1785+
incrementalFlag: "false",
1786+
expectedConfig: wrappers.SastConfig{
1787+
FastScanMode: "false",
1788+
Incremental: "false",
1789+
},
1790+
},
1791+
{
1792+
name: "Fast scan and Incremental scan both true",
1793+
requiredIncrementalSet: true,
1794+
requiredFastScanSet: true,
1795+
fastScanFlag: "true",
1796+
incrementalFlag: "true",
1797+
expectedConfig: wrappers.SastConfig{
1798+
FastScanMode: "true",
1799+
Incremental: "true",
1800+
},
1801+
},
1802+
{
1803+
name: "Fast scan and Incremental not set",
1804+
requiredIncrementalSet: false,
1805+
requiredFastScanSet: false,
1806+
expectedConfig: wrappers.SastConfig{},
1807+
},
1808+
{
1809+
name: "Fast scan is true and Incremental is false",
1810+
requiredIncrementalSet: true,
1811+
requiredFastScanSet: true,
1812+
fastScanFlag: "true",
1813+
incrementalFlag: "false",
1814+
expectedConfig: wrappers.SastConfig{
1815+
FastScanMode: "true",
1816+
Incremental: "false",
1817+
},
1818+
},
1819+
{
1820+
name: "Fast scan is false and Incremental is true",
1821+
requiredIncrementalSet: true,
1822+
requiredFastScanSet: true,
1823+
fastScanFlag: "false",
1824+
incrementalFlag: "true",
1825+
expectedConfig: wrappers.SastConfig{
1826+
FastScanMode: "false",
1827+
Incremental: "true",
1828+
},
1829+
},
1830+
{
1831+
name: "Fast scan is not set and Incremental is true",
1832+
requiredIncrementalSet: true,
1833+
incrementalFlag: "true",
1834+
expectedConfig: wrappers.SastConfig{
1835+
Incremental: "true",
1836+
},
1837+
},
1838+
{
1839+
name: "Fast scan is true and Incremental is not set",
1840+
requiredFastScanSet: true,
1841+
fastScanFlag: "true",
1842+
expectedConfig: wrappers.SastConfig{
1843+
FastScanMode: "true",
1844+
},
1845+
},
1846+
}
1847+
1848+
oldActualScanTypes := actualScanTypes
1849+
1850+
defer func() {
1851+
actualScanTypes = oldActualScanTypes
1852+
}()
1853+
1854+
for _, tt := range tests {
1855+
actualScanTypes = "sast,sca,kics,scs"
1856+
t.Run(tt.name, func(t *testing.T) {
1857+
cmdCommand := &cobra.Command{
1858+
Use: "scan",
1859+
Short: "Scan a project",
1860+
Long: `Scan a project`,
1861+
}
1862+
cmdCommand.PersistentFlags().Bool(commonParams.SastFastScanFlag, false, "Fast scan flag")
1863+
cmdCommand.PersistentFlags().Bool(commonParams.IncrementalSast, false, "Incremental scan flag")
1864+
1865+
_ = cmdCommand.Execute()
1866+
1867+
if tt.requiredFastScanSet {
1868+
_ = cmdCommand.PersistentFlags().Set(commonParams.SastFastScanFlag, tt.fastScanFlag)
1869+
}
1870+
if tt.requiredIncrementalSet {
1871+
_ = cmdCommand.PersistentFlags().Set(commonParams.IncrementalSast, tt.incrementalFlag)
1872+
}
1873+
1874+
result := addSastScan(cmdCommand, resubmitConfig)
1875+
1876+
actualSastConfig := wrappers.SastConfig{}
1877+
for key, value := range result {
1878+
if key == resultsMapType {
1879+
assert.Equal(t, commonParams.SastType, value)
1880+
} else if key == resultsMapValue {
1881+
actualSastConfig = *value.(*wrappers.SastConfig)
1882+
}
1883+
}
1884+
1885+
if !reflect.DeepEqual(actualSastConfig, tt.expectedConfig) {
1886+
t.Errorf("Expected %+v, but got %+v", tt.expectedConfig, actualSastConfig)
1887+
}
1888+
})
1889+
}
1890+
}
1891+
17691892
func TestValidateScanTypes(t *testing.T) {
17701893
tests := []struct {
17711894
name string

internal/wrappers/export-http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (e *ExportHTTPWrapper) GetExportReportStatus(reportID string) (*ExportPolli
134134
return &model, nil
135135
case http.StatusNotFound:
136136
_ = resp.Body.Close()
137-
time.Sleep(time.Second)
137+
time.Sleep(retryInterval)
138138
default:
139139
_ = resp.Body.Close()
140140
return nil, errors.Errorf("response status code %d", resp.StatusCode)

0 commit comments

Comments
 (0)