mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
fix per-module rego version lookup (#8799)
Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
This commit is contained in:
+1
-1
@@ -780,7 +780,7 @@ func erasePolicies(ctx context.Context, store storage.Store, txn storage.Transac
|
||||
}
|
||||
|
||||
getRegoVersion := func(modId string) (ast.RegoVersion, bool) {
|
||||
info, ok := modulesInfo[modId]
|
||||
info, ok := modulesInfo[strings.TrimPrefix(modId, "/")]
|
||||
if !ok {
|
||||
return ast.RegoUndefined, false
|
||||
}
|
||||
|
||||
@@ -4278,6 +4278,38 @@ func TestActivate_DefaultRegoVersion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Regression test for https://github.com/open-policy-agent/opa/issues/8797.
|
||||
func TestActivate_PreservesPerModuleRegoVersionWithLeadingSlashID(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
store := mock.New()
|
||||
|
||||
v1Module := `package test
|
||||
|
||||
p contains 42`
|
||||
|
||||
policyID := "/test/policy.rego"
|
||||
txn := storage.NewTransactionOrDie(ctx, store, storage.WriteParams)
|
||||
if err := store.UpsertPolicy(ctx, txn, policyID, []byte(v1Module)); err != nil {
|
||||
t.Fatalf("UpsertPolicy failed: %v", err)
|
||||
}
|
||||
if err := write(ctx, store, txn, moduleRegoVersionPath(policyID), int64(ast.RegoV1.Int())); err != nil {
|
||||
t.Fatalf("writing rego_version failed: %v", err)
|
||||
}
|
||||
if err := store.Commit(ctx, txn); err != nil {
|
||||
t.Fatalf("commit failed: %v", err)
|
||||
}
|
||||
|
||||
mustActivate(t, store, &ActivateOpts{
|
||||
Compiler: ast.NewCompiler().WithDefaultRegoVersion(ast.RegoV0CompatV1),
|
||||
ParserOptions: ast.ParserOptions{RegoVersion: ast.RegoV0},
|
||||
Bundles: map[string]*Bundle{
|
||||
"other": {
|
||||
Manifest: Manifest{Roots: &[]string{"other"}},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestDeactivate_DefaultRegoVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
note string
|
||||
|
||||
Reference in New Issue
Block a user