Skip to content

Commit

Permalink
tester/runner: Fix panic'ing case in utility function. (open-policy-a…
Browse files Browse the repository at this point in the history
…gent#5497)

This commit fixes a panic from a utility function in the `opa test`
codepath. After the ref-heads change in open-policy-agent#4660, this particular
function could be fed a ref that it didn't know how to work with,
such as from the innocuous line `a[0] := 1`, and it would then panic.

This was fixed by returning a dummy value instead of panic'ing.

Fixes: open-policy-agent#5496

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
  • Loading branch information
philipaconrad committed Dec 21, 2022
1 parent 7900951 commit a08934d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tester/runner.go
Expand Up @@ -437,7 +437,7 @@ func ruleName(h *ast.Head) string {
case ast.String:
return string(last)
default:
panic("unreachable")
return ""
}
}

Expand Down
6 changes: 6 additions & 0 deletions tester/runner_test.go
Expand Up @@ -81,6 +81,11 @@ func testRun(t *testing.T, conf testRunConfig) map[string]*ast.Module {
a.b.test_duplicate { false }
a.b.test_duplicate { true }
a.b.test_duplicate { true }`,
// Regression test for issue #5496.
"/d_test.rego": `package test
a[0] := 1
test_pass { true }`,
}

tests := expectedTestResults{
Expand All @@ -96,6 +101,7 @@ func testRun(t *testing.T, conf testRunConfig) map[string]*ast.Module {
{"data.baz", "a.b.test_duplicate"}: {false, true, false},
{"data.baz", "a.b[\"test_duplicate#01\"]"}: {false, false, false},
{"data.baz", "a.b[\"test_duplicate#02\"]"}: {false, false, false},
{"data.test", "test_pass"}: {false, false, false},
}

var modules map[string]*ast.Module
Expand Down

0 comments on commit a08934d

Please sign in to comment.