Skip to content

Fix/ast 100708 sca resolver params (AST-100708) #1195

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strconv"
"strings"
"time"
"unicode"

"github.com/checkmarx/ast-cli/internal/commands/asca"
"github.com/checkmarx/ast-cli/internal/commands/scarealtime"
Expand Down Expand Up @@ -1551,9 +1552,9 @@ func runScaResolver(sourceDir, scaResolver, scaResolverParams, projectName strin
scaResolverResultsFile,
}
if scaResolverParams != "" {
args = append(args, scaResolverParams)
parsedscaResolverParams := parseArgs(scaResolverParams)
args = append(args, parsedscaResolverParams...)
}

log.Println(fmt.Sprintf("Using SCA resolver: %s %v", scaResolver, args))
out, err := exec.Command(scaResolver, args...).Output()
logger.PrintIfVerbose(string(out))
Expand Down Expand Up @@ -1727,6 +1728,7 @@ func getScaResolverFlags(cmd *cobra.Command) (scaResolverParams, scaResolver str
scaResolver = ""
scaResolverParams = ""
}
logger.PrintfIfVerbose("HM:: in getScaResolverFlags scaResolverParams:: %v", scaResolverParams)
return scaResolverParams, scaResolver
}

Expand Down Expand Up @@ -2973,3 +2975,34 @@ func validateBooleanString(value string) error {
}
return nil
}

func parseArgs(input string) []string {
var args []string
var current strings.Builder
var quote rune
inQuotes := false

for i, r := range input {
switch {
case (r == '\'' || r == '"') && !inQuotes:
inQuotes = true
quote = r
case r == quote && inQuotes:
inQuotes = false
case unicode.IsSpace(r) && !inQuotes:
if current.Len() > 0 {
args = append(args, current.String())
current.Reset()
}
default:
current.WriteRune(r)
}

// Append last token if input ends
if i == len(input)-1 && current.Len() > 0 {
args = append(args, current.String())
}
}

return args
}
19 changes: 19 additions & 0 deletions internal/commands/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2237,3 +2237,22 @@ func TestCreateScanWith_ScaResolver_Source_as_Zip(t *testing.T) {
err := execCmdNotNilAssertion(t, baseArgs...)
assert.Assert(t, strings.Contains(err.Error(), ScaResolverZipNotSupportedErr), err.Error())
}

func Test_parseArgs(t *testing.T) {
tests := []struct {
inputString string
lenOfArgs int
}{
{"hitesh", 1},
{`test test1`, 2},
{"--gradle-parameters='-Prepository.proxy.url=123 -Prepository.proxy.username=123 -Prepository.proxy.password=123' --log-level Debug", 3},
}

for _, test := range tests {
fmt.Println("test ::", test)
result := parseArgs(test.inputString)
if len(result) != test.lenOfArgs {
t.Errorf(" test case failed for params %v", test)
}
}
}
Loading