Skip to content

Commit ac51713

Browse files
- Fixed go imports
- Added trimmed space condition for key
1 parent b0e7af9 commit ac51713

5 files changed

Lines changed: 26 additions & 25 deletions

File tree

internal/commands/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package commands
22

33
import (
44
"fmt"
5-
"github.com/checkmarx/ast-cli/internal/wrappers/utils"
5+
66
"io"
77
"log"
88
"os"
@@ -16,6 +16,7 @@ import (
1616
"github.com/checkmarx/ast-cli/internal/params"
1717
"github.com/checkmarx/ast-cli/internal/wrappers/bitbucketserver"
1818
"github.com/checkmarx/ast-cli/internal/wrappers/configuration"
19+
"github.com/checkmarx/ast-cli/internal/wrappers/utils"
1920
"github.com/pkg/errors"
2021

2122
"github.com/checkmarx/ast-cli/internal/wrappers"

internal/services/asca.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ package services
33
import (
44
"encoding/json"
55
"fmt"
6+
"net"
7+
"os"
8+
"os/exec"
9+
"path/filepath"
10+
"strings"
11+
"time"
612

713
"github.com/checkmarx/ast-cli/internal/commands/asca/ascaconfig"
814
"github.com/checkmarx/ast-cli/internal/logger"
@@ -15,12 +21,6 @@ import (
1521
getport "github.com/jsumners/go-getport"
1622
"github.com/pkg/errors"
1723
"github.com/spf13/viper"
18-
"net"
19-
"os"
20-
"os/exec"
21-
"path/filepath"
22-
"strings"
23-
"time"
2424
)
2525

2626
const (

internal/services/osinstaller/os-installer-structs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package osinstaller
22

33
import (
4-
"github.com/checkmarx/ast-cli/internal/logger"
54
"os"
65
"path/filepath"
6+
7+
"github.com/checkmarx/ast-cli/internal/logger"
78
)
89

910
type InstallationConfiguration struct {

internal/wrappers/utils/utils.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func SetOptionalParam(key, value string) {
4848
mutex.Lock()
4949
defer mutex.Unlock()
5050
value = strings.TrimSpace(value)
51-
if _, ok := allowedOptionalKeys[strings.TrimSpace(key)]; ok {
51+
key = strings.TrimSpace(key)
52+
if _, ok := allowedOptionalKeys[key]; ok {
5253
optionalParams[key] = value
5354
}
5455
}
@@ -63,9 +64,9 @@ func hasOptionalParam(key string) bool {
6364
func GetOptionalParam(key string) string {
6465
mutex.RLock()
6566
defer mutex.RUnlock()
66-
key = strings.TrimSpace(key)
67-
if hasOptionalParam(key) {
68-
return optionalParams[key]
67+
trimmedKey := strings.TrimSpace(key)
68+
if hasOptionalParam(trimmedKey) {
69+
return optionalParams[trimmedKey]
6970
}
7071
return ""
7172
}

internal/wrappers/utils/utils_test.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
"testing"
77
)
88

9+
const (
10+
ascaLocationKey = "asca-location"
11+
)
12+
913
func TestCleanURL_CleansCorrectly(t *testing.T) {
1014
uri := "https://codebashing.checkmarx.com/courses/java/////lessons/sql_injection/////"
1115
want := "https://codebashing.checkmarx.com/courses/java/lessons/sql_injection"
@@ -170,7 +174,7 @@ func clearOptionalParams() {
170174

171175
func TestSetAndGetAllowedKey(t *testing.T) {
172176
clearOptionalParams()
173-
key := "asca-location"
177+
key := ascaLocationKey
174178
value := "location-1"
175179

176180
SetOptionalParam(key, value)
@@ -206,23 +210,17 @@ func TestSetWithTrimmedKeyBehavior(t *testing.T) {
206210
clearOptionalParams()
207211

208212
originalKey := " asca-location "
209-
trimmedKey := "asca-location"
213+
trimmedKey := ascaLocationKey
210214
value := "trimmed-value"
211215

212216
SetOptionalParam(originalKey, value)
213217

214-
if !hasOptionalParam(originalKey) {
215-
t.Fatalf("expected hasOptionalParam(%q) to be true", originalKey)
216-
}
217218
if got := GetOptionalParam(originalKey); got != value {
218219
t.Fatalf("expected GetOptionalParam(%q) == %q, got %q", originalKey, value, got)
219220
}
220221

221-
if hasOptionalParam(trimmedKey) {
222-
t.Fatalf("did not expect hasOptionalParam(%q) to be true", trimmedKey)
223-
}
224-
if got := GetOptionalParam(trimmedKey); got != "" {
225-
t.Fatalf("expected GetOptionalParam(%q) == empty, got %q", trimmedKey, got)
222+
if got := GetOptionalParam(trimmedKey); got != value {
223+
t.Fatalf("expected GetOptionalParam(%q) == %q, got %q", originalKey, value, got)
226224
}
227225
}
228226

@@ -235,16 +233,16 @@ func TestConcurrentSetOptionalParam(t *testing.T) {
235233
wg.Add(1)
236234
go func(i int) {
237235
defer wg.Done()
238-
SetOptionalParam("asca-location", "v")
236+
SetOptionalParam(ascaLocationKey, "v")
239237
SetOptionalParam("not-allowed", "x")
240238
}(i)
241239
}
242240
wg.Wait()
243241

244-
if !hasOptionalParam("asca-location") {
242+
if !hasOptionalParam(ascaLocationKey) {
245243
t.Fatalf("expected hasOptionalParam(%q) to be true after concurrent sets", "asca-location")
246244
}
247245
if GetOptionalParam("asca-location") != "v" {
248-
t.Fatalf("expected GetOptionalParam(%q) == %q", "asca-location", "v")
246+
t.Fatalf("expected GetOptionalParam(%q) == %q", ascaLocationKey, "v")
249247
}
250248
}

0 commit comments

Comments
 (0)