Files
releases/v1/test/authz/authz_test.go
T
Ville Vesilehto f77322b3fb build: bump Go version requirement to 1.24 (#7839)
Go 1.23 is no longer supported as per Go release policy.

Changes:

- Use Go v1.24.6 as the project SDK requirement
- Apply lint fixes for Go 1.24
- Fix "non-constant format string in call" issues as seen in CI.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-08-24 09:02:09 +02:00

55 lines
1.2 KiB
Go

// Copyright 2017 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package authz
import (
"testing"
"github.com/open-policy-agent/opa/v1/ast"
"github.com/open-policy-agent/opa/v1/rego"
"github.com/open-policy-agent/opa/v1/storage"
"github.com/open-policy-agent/opa/v1/storage/inmem"
)
func TestAuthz(t *testing.T) {
profile := DataSetProfile{
NumTokens: 1000,
NumPaths: 10,
}
ctx := t.Context()
data := GenerateDataset(profile)
store := inmem.NewFromObject(data)
txn := storage.NewTransactionOrDie(ctx, store)
compiler := ast.NewCompiler()
module := ast.MustParseModule(Policy)
compiler.Compile(map[string]*ast.Module{"": module})
if compiler.Failed() {
t.Fatalf("Unexpected error(s): %v", compiler.Errors)
}
input, expected := GenerateInput(profile, ForbidPath)
r := rego.New(
rego.Compiler(compiler),
rego.Store(store),
rego.Transaction(txn),
rego.Input(input),
rego.Query(AllowQuery),
)
rs, err := r.Eval(ctx)
if err != nil {
t.Fatalf("Unexpected error(s): %v", err)
}
if rs.Allowed() != expected {
t.Fatalf("Unexpected result: want %v, got %v", expected, rs.Allowed())
}
}