-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support scs engine In scan create Resubmit command (AST-63906) #840
Changes from 5 commits
5004427
5916275
d4bb15d
66e8edf
7babb9a
9f7cbbb
d406d06
bd3e8e0
15a0a97
5ee272f
3112218
d0f97b2
8d065e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ | |
resultsMapValue = "value" | ||
resultsMapType = "type" | ||
trueString = "true" | ||
configTwoms = "2ms" | ||
falseString = "false" | ||
maxPollingWaitTime = 60 | ||
engineNotAllowed = "It looks like the \"%s\" scan type does not exist or you are trying to run a scan without the \"%s\" package license." + | ||
|
@@ -779,7 +780,7 @@ | |
configArr = append(configArr, containersConfig) | ||
} | ||
|
||
var SCSConfig, scsErr = addSCSScan(cmd) | ||
var SCSConfig, scsErr = addSCSScan(cmd, resubmitConfig) | ||
if scsErr != nil { | ||
return scsErr | ||
} else if SCSConfig != nil { | ||
|
@@ -974,15 +975,33 @@ | |
return nil | ||
} | ||
|
||
func addSCSScan(cmd *cobra.Command) (map[string]interface{}, error) { | ||
if scanTypeEnabled(commonParams.ScsType) { | ||
func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[string]interface{}, error) { | ||
if scanTypeEnabled(commonParams.ScsType) || scanTypeEnabled(commonParams.MicroEnginesType) { | ||
SCSMapConfig := make(map[string]interface{}) | ||
SCSConfig := wrappers.SCSConfig{} | ||
SCSMapConfig[resultsMapType] = commonParams.MicroEnginesType // scs is still microengines in the scans API | ||
userScanTypes, _ := cmd.Flags().GetString(commonParams.ScanTypes) | ||
SCSRepoToken, _ := cmd.Flags().GetString(commonParams.SCSRepoTokenFlag) | ||
SCSRepoURL, _ := cmd.Flags().GetString(commonParams.SCSRepoURLFlag) | ||
SCSEngines, _ := cmd.Flags().GetString(commonParams.SCSEnginesFlag) | ||
if resubmitConfig != nil { | ||
for _, config := range resubmitConfig { | ||
resubmitTwoms := config.Value[configTwoms] | ||
if resubmitTwoms != nil { | ||
SCSConfig.Twoms = resubmitTwoms.(string) | ||
} | ||
SCSConfig.RepoURL = SCSRepoURL | ||
SCSConfig.RepoToken = SCSRepoToken | ||
resubmitScoreCard := config.Value[ScsScoreCardType] | ||
if resubmitScoreCard == trueString && SCSRepoToken != "" && SCSRepoURL != "" { | ||
SCSConfig.Scorecard = trueString | ||
} else { | ||
SCSConfig.Scorecard = falseString | ||
} | ||
} | ||
SCSMapConfig[resultsMapValue] = &SCSConfig | ||
return SCSMapConfig, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont you need the config builder to finish his work first? |
||
} | ||
if SCSEngines != "" { | ||
SCSEnginesTypes := strings.Split(SCSEngines, ",") | ||
for _, engineType := range SCSEnginesTypes { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -664,6 +664,89 @@ func TestAddScaScan(t *testing.T) { | |
t.Errorf("Expected %+v, but got %+v", scaMapConfig, result) | ||
} | ||
} | ||
func TestAddSCSScan_ResubmitWithOutScorecardFlags_ShouldPass(t *testing.T) { | ||
cmdCommand := &cobra.Command{ | ||
Use: "scan", | ||
Short: "Scan a project", | ||
} | ||
cmdCommand.PersistentFlags().String(commonParams.ScanTypes, "", "Scan types") | ||
cmdCommand.PersistentFlags().String(commonParams.SCSRepoTokenFlag, "", "SCS Repo Token") | ||
cmdCommand.PersistentFlags().String(commonParams.SCSRepoURLFlag, "", "SCS Repo URL") | ||
|
||
_ = cmdCommand.Execute() | ||
|
||
_ = cmdCommand.Flags().Set(commonParams.ScanTypes, commonParams.ScsType) | ||
_ = cmdCommand.Flags().Set(commonParams.SCSRepoURLFlag, "") | ||
_ = cmdCommand.Flags().Set(commonParams.SCSRepoTokenFlag, "") | ||
|
||
resubmitConfig := []wrappers.Config{ | ||
{ | ||
Type: commonParams.ScsType, | ||
Value: map[string]interface{}{ | ||
configTwoms: "true", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trueString |
||
ScsScoreCardType: falseString, | ||
}, | ||
}, | ||
} | ||
|
||
result, _ := addSCSScan(cmdCommand, resubmitConfig) | ||
|
||
expectedConfig := wrappers.SCSConfig{ | ||
Twoms: "true", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trueString |
||
Scorecard: falseString, | ||
} | ||
|
||
expectedMapConfig := make(map[string]interface{}) | ||
expectedMapConfig[resultsMapType] = commonParams.MicroEnginesType | ||
expectedMapConfig[resultsMapValue] = &expectedConfig | ||
|
||
if !reflect.DeepEqual(result, expectedMapConfig) { | ||
t.Errorf("Expected %+v, but got %+v", expectedMapConfig, result) | ||
} | ||
} | ||
|
||
func TestAddSCSScan_ResubmitWithScorecardFlags_ShouldPass(t *testing.T) { | ||
cmdCommand := &cobra.Command{ | ||
Use: "scan", | ||
Short: "Scan a project", | ||
} | ||
cmdCommand.PersistentFlags().String(commonParams.ScanTypes, "", "Scan types") | ||
cmdCommand.PersistentFlags().String(commonParams.SCSRepoTokenFlag, "", "SCS Repo Token") | ||
cmdCommand.PersistentFlags().String(commonParams.SCSRepoURLFlag, "", "SCS Repo URL") | ||
|
||
_ = cmdCommand.Execute() | ||
|
||
_ = cmdCommand.Flags().Set(commonParams.ScanTypes, commonParams.ScsType) | ||
_ = cmdCommand.Flags().Set(commonParams.SCSRepoURLFlag, dummyRepo) | ||
_ = cmdCommand.Flags().Set(commonParams.SCSRepoTokenFlag, dummyToken) | ||
|
||
resubmitConfig := []wrappers.Config{ | ||
{ | ||
Type: commonParams.ScsType, | ||
Value: map[string]interface{}{ | ||
configTwoms: "true", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trueString |
||
ScsScoreCardType: trueString, | ||
}, | ||
}, | ||
} | ||
|
||
result, _ := addSCSScan(cmdCommand, resubmitConfig) | ||
|
||
expectedConfig := wrappers.SCSConfig{ | ||
Twoms: "true", | ||
Scorecard: trueString, | ||
RepoToken: dummyToken, | ||
RepoURL: dummyRepo, | ||
} | ||
|
||
expectedMapConfig := make(map[string]interface{}) | ||
expectedMapConfig[resultsMapType] = commonParams.MicroEnginesType | ||
expectedMapConfig[resultsMapValue] = &expectedConfig | ||
|
||
if !reflect.DeepEqual(result, expectedMapConfig) { | ||
t.Errorf("Expected %+v, but got %+v", expectedMapConfig, result) | ||
} | ||
} | ||
|
||
func TestAddSastScan_WithFastScanFlag_ShouldPass(t *testing.T) { | ||
var resubmitConfig []wrappers.Config | ||
|
@@ -809,6 +892,7 @@ func TestCreateScan_WithSCSScorecard_ShouldFail(t *testing.T) { | |
} | ||
|
||
func TestCreateScan_WithSCSSecretDetectionAndScorecard_scsMapHasBoth(t *testing.T) { | ||
var resubmitConfig []wrappers.Config | ||
cmdCommand := &cobra.Command{ | ||
Use: "scan", | ||
Short: "Scan a project", | ||
|
@@ -822,7 +906,7 @@ func TestCreateScan_WithSCSSecretDetectionAndScorecard_scsMapHasBoth(t *testing. | |
_ = cmdCommand.Flags().Set(commonParams.SCSRepoTokenFlag, dummyToken) | ||
_ = cmdCommand.Flags().Set(commonParams.SCSRepoURLFlag, dummyRepo) | ||
|
||
result, _ := addSCSScan(cmdCommand) | ||
result, _ := addSCSScan(cmdCommand, resubmitConfig) | ||
|
||
scsConfig := wrappers.SCSConfig{ | ||
Twoms: "true", | ||
|
@@ -840,6 +924,7 @@ func TestCreateScan_WithSCSSecretDetectionAndScorecard_scsMapHasBoth(t *testing. | |
} | ||
|
||
func TestCreateScan_WithSCSSecretDetection_scsMapHasSecretDetection(t *testing.T) { | ||
var resubmitConfig []wrappers.Config | ||
cmdCommand := &cobra.Command{ | ||
Use: "scan", | ||
Short: "Scan a project", | ||
|
@@ -849,7 +934,7 @@ func TestCreateScan_WithSCSSecretDetection_scsMapHasSecretDetection(t *testing.T | |
_ = cmdCommand.Execute() | ||
_ = cmdCommand.Flags().Set(commonParams.SCSEnginesFlag, "secret-detection") | ||
|
||
result, _ := addSCSScan(cmdCommand) | ||
result, _ := addSCSScan(cmdCommand, resubmitConfig) | ||
|
||
scsConfig := wrappers.SCSConfig{ | ||
Twoms: "true", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract this scope to a new method - createSCSResubmitConfig(...).
This will make the function more readable and will answer the Single Responsibility Principle.
Also, it will probably fix your lint error