Skip to content

Commit 2ad78d5

Browse files
Merge pull request #1007 from Checkmarx/bug/AST-73370
Error message for SCS and Enterprise Secret (AST-73370)
2 parents 4c614be + d7cde62 commit 2ad78d5

File tree

4 files changed

+72
-10
lines changed

4 files changed

+72
-10
lines changed

.github/workflows/ai-code-review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
code_review:
11-
uses: Checkmarx/plugins-release-workflow/.github/workflows/ai-code-review.yml@add-ai-code-review
11+
uses: Checkmarx/plugins-release-workflow/.github/workflows/ai-code-review.yml@main
1212
with:
1313
open_ai_model: "gpt-4-1106-preview"
1414
exclude_pattern: ""

internal/commands/scan.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,13 +1086,6 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu
10861086
userScanTypes = strings.Replace(strings.ToLower(userScanTypes), commonParams.ContainersTypeFlag, commonParams.ContainersType, 1)
10871087
userSCSScanTypes = strings.Replace(strings.ToLower(userSCSScanTypes), commonParams.SCSEnginesFlag, commonParams.ScsType, 1)
10881088

1089-
SCSScanTypes = strings.Split(userSCSScanTypes, ",")
1090-
if slices.Contains(SCSScanTypes, ScsSecretDetectionType) && !allowedEngines[commonParams.EnterpriseSecretsType] {
1091-
keys := reflect.ValueOf(allowedEngines).MapKeys()
1092-
err = errors.Errorf(engineNotAllowed, ScsSecretDetectionType, ScsSecretDetectionType, keys)
1093-
return err
1094-
}
1095-
10961089
scanTypes = strings.Split(userScanTypes, ",")
10971090
for _, scanType := range scanTypes {
10981091
if !allowedEngines[scanType] || (scanType == commonParams.ContainersType && !(containerEngineCLIEnabled.Status)) {
@@ -1101,6 +1094,14 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu
11011094
return err
11021095
}
11031096
}
1097+
1098+
SCSScanTypes = strings.Split(userSCSScanTypes, ",")
1099+
if slices.Contains(SCSScanTypes, ScsSecretDetectionType) && !allowedEngines[commonParams.EnterpriseSecretsType] {
1100+
keys := reflect.ValueOf(allowedEngines).MapKeys()
1101+
err = errors.Errorf(engineNotAllowed, ScsSecretDetectionType, ScsSecretDetectionType, keys)
1102+
return err
1103+
}
1104+
11041105
} else {
11051106
for k := range allowedEngines {
11061107
if k == commonParams.ContainersType && !(containerEngineCLIEnabled.Status) {

internal/commands/scan_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,3 +1888,60 @@ func TestAddSastScan_ScanFlags(t *testing.T) {
18881888
})
18891889
}
18901890
}
1891+
1892+
func TestValidateScanTypes(t *testing.T) {
1893+
tests := []struct {
1894+
name string
1895+
userScanTypes string
1896+
userSCSScanTypes string
1897+
allowedEngines map[string]bool
1898+
containerEngineCLIEnabled bool
1899+
expectedError string
1900+
}{
1901+
{
1902+
name: "No licenses available",
1903+
userScanTypes: "scs",
1904+
userSCSScanTypes: "sast,secret-detection",
1905+
allowedEngines: map[string]bool{"scs": false, "enterprise-secrets": false},
1906+
containerEngineCLIEnabled: true,
1907+
expectedError: "It looks like the \"scs\" scan type does",
1908+
},
1909+
{
1910+
name: "SCS license available, secret-detection not available",
1911+
userScanTypes: "scs",
1912+
userSCSScanTypes: "secret-detection",
1913+
allowedEngines: map[string]bool{"scs": true, "enterprise-secrets": false},
1914+
containerEngineCLIEnabled: true,
1915+
expectedError: "It looks like the \"secret-detection\" scan type does not exist",
1916+
},
1917+
{
1918+
name: "All licenses available",
1919+
userScanTypes: "scs",
1920+
userSCSScanTypes: "secret-detection",
1921+
allowedEngines: map[string]bool{"scs": true, "enterprise-secrets": true},
1922+
containerEngineCLIEnabled: true,
1923+
expectedError: "",
1924+
},
1925+
}
1926+
1927+
for _, tt := range tests {
1928+
t.Run(tt.name, func(t *testing.T) {
1929+
cmd := &cobra.Command{}
1930+
cmd.Flags().String(commonParams.ScanTypes, tt.userScanTypes, "")
1931+
cmd.Flags().String(commonParams.SCSEnginesFlag, tt.userSCSScanTypes, "")
1932+
1933+
jwtWrapper := &mock.JWTMockWrapper{
1934+
CustomGetAllowedEngines: func(featureFlagsWrapper wrappers.FeatureFlagsWrapper) (map[string]bool, error) {
1935+
return tt.allowedEngines, nil
1936+
},
1937+
}
1938+
featureFlagsWrapper := &mock.FeatureFlagsMockWrapper{}
1939+
err := validateScanTypes(cmd, jwtWrapper, featureFlagsWrapper)
1940+
if tt.expectedError != "" {
1941+
assert.ErrorContains(t, err, tt.expectedError)
1942+
} else {
1943+
assert.NilError(t, err)
1944+
}
1945+
})
1946+
}
1947+
}

internal/wrappers/mock/jwt-helper-mock.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import (
77
)
88

99
type JWTMockWrapper struct {
10-
AIEnabled int
10+
AIEnabled int
11+
CustomGetAllowedEngines func(wrappers.FeatureFlagsWrapper) (map[string]bool, error)
1112
}
1213

1314
const AIProtectionDisabled = 1
1415

1516
// GetAllowedEngines mock for tests
16-
func (*JWTMockWrapper) GetAllowedEngines(featureFlagsWrapper wrappers.FeatureFlagsWrapper) (allowedEngines map[string]bool, err error) {
17+
func (j *JWTMockWrapper) GetAllowedEngines(featureFlagsWrapper wrappers.FeatureFlagsWrapper) (allowedEngines map[string]bool, err error) {
18+
if j.CustomGetAllowedEngines != nil {
19+
return j.CustomGetAllowedEngines(featureFlagsWrapper)
20+
}
1721
allowedEngines = make(map[string]bool)
1822
engines := []string{"sast", "iac-security", "sca", "api-security", "containers", "scs"}
1923
for _, value := range engines {

0 commit comments

Comments
 (0)