Skip to content

Commit e7376a7

Browse files
Fix/not enabled scs engine being triggered with feature flag SSCS_NEW_LICENSING_ENABLED on (AST-125713) (#1375)
1 parent b4ffd85 commit e7376a7

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

internal/commands/scan.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,9 +1371,12 @@ func isScorecardRunnable(isScsEnginesFlagSet, scsScorecardSelected bool, scsRepo
13711371

13721372
func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config, scsLicensingV2, hasRepositoryHealthLicense,
13731373
hasSecretDetectionLicense, hasEnterpriseSecretsLicense bool) (map[string]interface{}, error) {
1374-
scsEnabled := scanTypeEnabled(commonParams.ScsType)
1375-
scsScorecardAllowed := isScsScorecardAllowed(scsLicensingV2, hasRepositoryHealthLicense, scsEnabled)
1376-
scsSecretDetectionAllowed := isScsSecretDetectionAllowed(scsLicensingV2, hasSecretDetectionLicense, hasEnterpriseSecretsLicense, scsEnabled)
1374+
scsEnabled := isScsEnabled(scsLicensingV2)
1375+
if !scsEnabled {
1376+
return nil, nil
1377+
}
1378+
scsScorecardAllowed := isScsScorecardAllowed(scsLicensingV2, hasRepositoryHealthLicense)
1379+
scsSecretDetectionAllowed := isScsSecretDetectionAllowed(scsLicensingV2, hasSecretDetectionLicense, hasEnterpriseSecretsLicense)
13771380
if !scsScorecardAllowed && !scsSecretDetectionAllowed {
13781381
return nil, nil
13791382
}
@@ -1429,18 +1432,26 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config, scsLicensi
14291432
return scsMapConfig, nil
14301433
}
14311434

1432-
func isScsScorecardAllowed(scsLicensingV2, hasRepositoryHealthLicense, hasScsLicense bool) bool {
1435+
func isScsEnabled(scsLicensingV2 bool) bool {
1436+
if scsLicensingV2 {
1437+
return scanTypeEnabled(commonParams.ScsType) || scanTypeEnabled(commonParams.SecretDetectionType) ||
1438+
scanTypeEnabled(commonParams.RepositoryHealthType)
1439+
}
1440+
return scanTypeEnabled(commonParams.ScsType)
1441+
}
1442+
1443+
func isScsScorecardAllowed(scsLicensingV2, hasRepositoryHealthLicense bool) bool {
14331444
if scsLicensingV2 {
14341445
return hasRepositoryHealthLicense
14351446
}
1436-
return hasScsLicense
1447+
return true
14371448
}
14381449

1439-
func isScsSecretDetectionAllowed(scsLicensingV2, hasSecretDetectionLicense, hasEnterpriseSecretsLicense, hasScsLicense bool) bool {
1450+
func isScsSecretDetectionAllowed(scsLicensingV2, hasSecretDetectionLicense, hasEnterpriseSecretsLicense bool) bool {
14401451
if scsLicensingV2 {
14411452
return hasSecretDetectionLicense
14421453
}
1443-
return hasScsLicense && hasEnterpriseSecretsLicense
1454+
return hasEnterpriseSecretsLicense
14441455
}
14451456

14461457
func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featureFlagsWrapper wrappers.FeatureFlagsWrapper) error {

internal/commands/scan_test.go

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,21 +3453,13 @@ func TestIsScsScorecardAllowed(t *testing.T) {
34533453
name string
34543454
scsLicensingV2 bool
34553455
hasRepositoryHealthLicense bool
3456-
hasScsLicense bool
34573456
expectedAllowed bool
34583457
}{
34593458
{
3460-
name: "scsLicensingV2 disabled and has scs license",
3459+
name: "scsLicensingV2 disabled",
34613460
scsLicensingV2: false,
3462-
hasScsLicense: true,
34633461
expectedAllowed: true,
34643462
},
3465-
{
3466-
name: "scsLicensingV2 disabled and does not have scs license",
3467-
scsLicensingV2: false,
3468-
hasScsLicense: false,
3469-
expectedAllowed: false,
3470-
},
34713463
{
34723464
name: "scsLicensingV2 enabled and has repository health license",
34733465
scsLicensingV2: true,
@@ -3484,7 +3476,7 @@ func TestIsScsScorecardAllowed(t *testing.T) {
34843476

34853477
for _, tt := range tests {
34863478
t.Run(tt.name, func(t *testing.T) {
3487-
actualAllowed := isScsScorecardAllowed(tt.scsLicensingV2, tt.hasRepositoryHealthLicense, tt.hasScsLicense)
3479+
actualAllowed := isScsScorecardAllowed(tt.scsLicensingV2, tt.hasRepositoryHealthLicense)
34883480
assert.Equal(t, tt.expectedAllowed, actualAllowed)
34893481
})
34903482
}
@@ -3496,28 +3488,18 @@ func TestIsScsSecretDetectionAllowed(t *testing.T) {
34963488
scsLicensingV2 bool
34973489
hasSecretDetectionLicense bool
34983490
hasEnterpriseSecretsLicense bool
3499-
hasScsLicense bool
35003491
expectedAllowed bool
35013492
}{
35023493
{
3503-
name: "scsLicensingV2 disabled and has scs and enterprise secrets license",
3494+
name: "scsLicensingV2 disabled and has enterprise secrets license",
35043495
scsLicensingV2: false,
35053496
hasEnterpriseSecretsLicense: true,
3506-
hasScsLicense: true,
35073497
expectedAllowed: true,
35083498
},
35093499
{
3510-
name: "scsLicensingV2 disabled and has enterprise secrets but does not have scs license",
3511-
scsLicensingV2: false,
3512-
hasEnterpriseSecretsLicense: true,
3513-
hasScsLicense: false,
3514-
expectedAllowed: false,
3515-
},
3516-
{
3517-
name: "scsLicensingV2 disabled and has scs license but does not have enterprise secrets license",
3500+
name: "scsLicensingV2 disabled but does not have enterprise secrets license",
35183501
scsLicensingV2: false,
35193502
hasEnterpriseSecretsLicense: false,
3520-
hasScsLicense: true,
35213503
expectedAllowed: false,
35223504
},
35233505
{
@@ -3536,7 +3518,7 @@ func TestIsScsSecretDetectionAllowed(t *testing.T) {
35363518

35373519
for _, tt := range tests {
35383520
t.Run(tt.name, func(t *testing.T) {
3539-
actualAllowed := isScsSecretDetectionAllowed(tt.scsLicensingV2, tt.hasSecretDetectionLicense, tt.hasEnterpriseSecretsLicense, tt.hasScsLicense)
3521+
actualAllowed := isScsSecretDetectionAllowed(tt.scsLicensingV2, tt.hasSecretDetectionLicense, tt.hasEnterpriseSecretsLicense)
35403522
assert.Equal(t, tt.expectedAllowed, actualAllowed)
35413523
})
35423524
}

0 commit comments

Comments
 (0)