Skip to content

Commit

Permalink
rego-v1: Future-proofing server pkg tests to be 1.0 compatible (#7029)
Browse files Browse the repository at this point in the history
Signed-off-by: Johan Fylling <[email protected]>
  • Loading branch information
johanfylling authored Sep 18, 2024
1 parent c39673b commit 8de480e
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 81 deletions.
33 changes: 17 additions & 16 deletions server/authorizer/authorizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,70 +48,70 @@ func TestBasic(t *testing.T) {
import data.system.tokens
allow = resp {
allow = resp if {
not undefined_case
}
resp["allowed"] = allowed {
resp["allowed"] = allowed if {
not undefined_case
not wrong_object
}
resp["reason"] = "custom reason" {
resp["reason"] = "custom reason" if {
input.path = ["reason"]
}
resp["reason"] = 0 {
resp["reason"] = 0 if {
input.path = ["reason", "wrong_type"]
}
resp["foo"] = "bar" {
resp["foo"] = "bar" if {
wrong_object
}
default allowed = false
allowed = allow_inner {
allowed = allow_inner if {
not undefined_case # undefined
not wrong_object # object response, wrong key
not input.path[0] = "reason" # custom reason
not conflict_error # eval errors
print("ok")
}
undefined_case {
undefined_case if {
input.path[0] = "undefined"
}
wrong_object {
wrong_object if {
input.path = ["reason", "wrong_object"]
}
conflict_error {
conflict_error if {
input.path[0] = "conflict_error"
{k: v | k = ["a", "a"][_]; [1, 2][v]}
}
default allow_inner = false
allow_inner {
allow_inner if {
valid_method
valid_path
}
valid_method {
valid_method if {
rights[_].access[_] = access_map[input.method]
}
valid_path {
valid_path if {
rights[_].path = "*"
}
valid_path {
valid_path if {
rights[_].path = input.path
}
rights[right] {
rights contains right if {
role = tokens[input.identity].roles[_]
right = all_rights[role][_]
}
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestBasic(t *testing.T) {
`
c := ast.NewCompiler().WithEnablePrintStatements(true)
c.Compile(map[string]*ast.Module{
"test.rego": ast.MustParseModule(module),
"test.rego": ast.MustParseModuleWithOpts(module, ast.ParserOptions{AllFutureKeywords: true}),
})
if c.Failed() {
t.Fatalf("Unexpected error compiling test module: %v", c.Errors)
Expand Down Expand Up @@ -472,8 +472,9 @@ func TestInterQueryCache(t *testing.T) {
compiler := func() *ast.Compiler {
module := fmt.Sprintf(`
package system.authz
import rego.v1
allow {
allow if {
http.send({
"method": "GET",
"url": "%v",
Expand Down
Loading

0 comments on commit 8de480e

Please sign in to comment.