Skip to content

Commit

Permalink
Merge branch 'main' into bug/elchanan/display-description-incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
elchananarb authored Aug 13, 2024
2 parents b9ff03e + c0c7d39 commit 3d006e2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ func setupScanHandler(cmd *cobra.Command, uploadsWrapper wrappers.UploadsWrapper
) {
zipFilePath := ""
scanHandler := wrappers.ScanHandler{}
scanHandler.Branch = viper.GetString(commonParams.BranchKey)
scanHandler.Branch = strings.TrimSpace(viper.GetString(commonParams.BranchKey))

uploadType := getUploadType(cmd)

Expand Down Expand Up @@ -2634,7 +2634,7 @@ func deprecatedFlagValue(cmd *cobra.Command, deprecatedFlagKey, inUseFlagKey str
}

func validateCreateScanFlags(cmd *cobra.Command) error {
branch := viper.GetString(commonParams.BranchKey)
branch := strings.TrimSpace(viper.GetString(commonParams.BranchKey))
if branch == "" {
return errors.Errorf("%s: Please provide a branch", failedCreating)
}
Expand Down
42 changes: 41 additions & 1 deletion test/integration/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/google/uuid"
"io"
"log"
"os"
Expand All @@ -29,7 +30,6 @@ import (
"github.com/checkmarx/ast-cli/internal/services"
"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/checkmarx/ast-cli/internal/wrappers/configuration"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/spf13/viper"
asserts "github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -1843,6 +1843,46 @@ func validateCheckmarxDomains(t *testing.T, usedDomainsInTests []string) {
}
}

func TestCreateScan_TwoScansWithSameBranchNameWithWhiteSpace_Success(t *testing.T) {
projectName := generateRandomProjectNameForScan()
args := []string{
scanCommand, "create",
flag(params.ProjectName), projectName,
flag(params.SourcesFlag), Zip,
flag(params.ScanTypes), "iac-security",
flag(params.BranchFlag), "dummy_branch",
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
}
_, projectID := executeCreateScan(t, args)
args2 := []string{
scanCommand, "create",
flag(params.ProjectName), projectName,
flag(params.SourcesFlag), Zip,
flag(params.ScanTypes), "iac-security",
flag(params.BranchFlag), " dummy_branch ",
}
err, _ := executeCommand(t, args2...)
assert.NilError(t, err)

response := listScanByProjectID(t, projectID)
assert.Assert(t, len(response) == 2)
for _, scan := range response {
assert.Equal(t, scan.Branch, "dummy_branch", "Branch name should be dummy_branch")
}
}
func listScanByProjectID(t *testing.T, projectID string) []wrappers.ScanResponseModel {
scanFilter := fmt.Sprintf("project-id=%s", projectID)
outputBuffer := executeCmdNilAssertion(
t,
"Getting the scan should pass",
"scan", scanList, flag(params.FormatFlag), printer.FormatJSON, flag(params.FilterFlag), scanFilter,
)
// Read response from buffer
var scanList []wrappers.ScanResponseModel
_ = unmarshall(t, outputBuffer, &scanList, "Reading scan response JSON should pass")
return scanList
}

func TestCreateAsyncScan_CallExportServiceBeforeScanFinishWithRetry_Success(t *testing.T) {
createASTIntegrationTestCommand(t)
configuration.LoadConfiguration()
Expand Down

0 comments on commit 3d006e2

Please sign in to comment.