Skip to content
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

Change IsAllowedEngine func to return true when packageEnforcementEnabled is false (AST-76112) #951

Merged
merged 10 commits into from
Dec 3, 2024
2 changes: 1 addition & 1 deletion .github/workflows/pr-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
exit 1
fi

if ! [[ "$PR_BRANCH" =~ ^(bug|feature|other)/ ]]; then
if ! [[ "$PR_BRANCH" =~ ^(bug|fix|feature|other)/ ]]; then
echo "::error::Branch name must start with 'bug/' or 'feature/' or 'other/'."
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Each line is a file pattern followed by one or more owners

# Specify the default owners for the entire repository
* @OrShamirCM @AlvoBen
* @AlvoBen @greensd4 @miryamfoiferCX
18 changes: 18 additions & 0 deletions internal/services/asca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

errorconstants "github.com/checkmarx/ast-cli/internal/constants/errors"
"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/checkmarx/ast-cli/internal/wrappers/grpcs"
"github.com/checkmarx/ast-cli/internal/wrappers/mock"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -130,3 +131,20 @@ func TestCreateASCAScanRequest_EngineRunningAndDefaultAgentAndNoLicense_Success(
assert.Nil(t, wrapperParams.ASCAWrapper.HealthCheck())
_ = wrapperParams.ASCAWrapper.ShutDown()
}

func TestCreateASCAScanRequest_EngineNotRunningAndPackageEnforcementFFOff_Success(t *testing.T) {
miryamfoiferCX marked this conversation as resolved.
Show resolved Hide resolved
port, err := getAvailablePort()
if err != nil {
t.Fatalf("Failed to get available port: %v", err)
}

mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.PackageEnforcementEnabled, Status: false}

wrapperParams := AscaWrappersParam{
JwtWrapper: wrappers.NewJwtWrapper(),
FeatureFlagsWrapper: &mock.FeatureFlagsMockWrapper{},
ASCAWrapper: grpcs.NewASCAGrpcWrapper(port),
}
err = checkLicense(false, wrapperParams)
assert.Nil(t, err)
}
2 changes: 1 addition & 1 deletion internal/wrappers/jwt-helper.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe return
if !flagResponse.Status {
return true, nil
}
jwtStruct, err := getJwtStruct()...

Early return if the feature flag is disabled, to avoid unnecessary nested logic

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!

Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (*JWTStruct) IsAllowedEngine(engine string, featureFlagsWrapper FeatureFlag
}
}
}
return false, nil
return true, nil
miryamfoiferCX marked this conversation as resolved.
Show resolved Hide resolved
}

func prepareEngines(engines []string) map[string]bool {
Expand Down
Loading