Skip to content
16 changes: 11 additions & 5 deletions internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ func getResubmitConfiguration(scansWrapper wrappers.ScansWrapper, projectID, use
var allScansModel *wrappers.ScansCollectionResponseModel
var errorModel *wrappers.ErrorModel
var err error
var config []wrappers.Config
params := make(map[string]string)
params["project-id"] = projectID
allScansModel, errorModel, err = scansWrapper.Get(params)
Expand All @@ -844,12 +845,17 @@ func getResubmitConfiguration(scansWrapper wrappers.ScansWrapper, projectID, use
if errorModel != nil {
return nil, errors.Errorf(services.ErrorCodeFormat, failedGettingAll, errorModel.Code, errorModel.Message)
}
config := allScansModel.Scans[0].Metadata.Configs
engines := allScansModel.Scans[0].Engines
// Check if there are no scan types sent using the flags, and use the latest scan engine types
if userScanTypes == "" {
actualScanTypes = strings.Join(engines, ",")

if len(allScansModel.Scans) > 0 {
scanModelResponse := allScansModel.Scans[0]
config = scanModelResponse.Metadata.Configs
engines := scanModelResponse.Engines
// Check if there are no scan types sent using the flags, and use the latest scan engine types
if userScanTypes == "" {
actualScanTypes = strings.Join(engines, ",")
}
}

return config, nil
}

Expand Down
11 changes: 11 additions & 0 deletions internal/commands/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,3 +1320,14 @@ func deleteOutputFile(file *os.File) {
logger.Printf("Failed to remove log file: %v", err)
}
}

func TestResubmitConfig_ProjectDoesNotExist_ReturnedEmptyConfig(t *testing.T) {
scanWrapper := mock.ScansMockWrapper{}
projectID := "non-existent-project"
userScanTypes := ""
cmd := createASTTestCommand()
cmd.PersistentFlags().String("project-name", "non-existent-project", "project name")
config, err := getResubmitConfiguration(&scanWrapper, projectID, userScanTypes)
assert.NilError(t, err)
assert.Equal(t, len(config), 0)
}
6 changes: 5 additions & 1 deletion internal/wrappers/mock/scans-mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ func (m *ScansMockWrapper) Create(scanModel *wrappers.Scan) (*wrappers.ScanRespo
}, nil, nil
}

func (m *ScansMockWrapper) Get(_ map[string]string) (
func (m *ScansMockWrapper) Get(scanParams map[string]string) (
*wrappers.ScansCollectionResponseModel,
*wrappers.ErrorModel,
error,
) {
if scanParams["project-id"] == "non-existent-project" {
return &wrappers.ScansCollectionResponseModel{}, nil, nil
}

fmt.Println("Called Get in ScansMockWrapper")
sastMapConfig := make(map[string]interface{})
sastMapConfig["incremental"] = "trueSastIncremental"
Expand Down
14 changes: 14 additions & 0 deletions test/integration/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1972,3 +1972,17 @@ func TestCreateAsyncScan_CallExportServiceBeforeScanFinishWithRetry_Success(t *t
asserts.Nil(t, err)
assert.Assert(t, exportRes != nil, "Export response should not be nil")
}

func TestCreateScanWithResubmitFlag_ProjectNotExist_ScanCreatedSuccessfullyWithDefaultConfig(t *testing.T) {
projectName := GenerateRandomProjectNameForScan()
args := []string{
scanCommand, "create",
flag(params.ProjectName), projectName,
flag(params.SourcesFlag), Zip,
flag(params.BranchFlag), "main",
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
flag(params.ScanResubmit),
}
err, _ := executeCommand(t, args...)
assert.NilError(t, err)
}
Loading