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

opa test panics when array ref present in test #5496

Closed
philipaconrad opened this issue Dec 20, 2022 · 0 comments · Fixed by #5497
Closed

opa test panics when array ref present in test #5496

philipaconrad opened this issue Dec 20, 2022 · 0 comments · Fixed by #5497
Labels

Comments

@philipaconrad
Copy link
Contributor

Short description

  • Originally reported offline by @istalker2
  • OPA version: v0.46.0+
  • Affects opa test only.

The opa test command apparently panics when fed an array reference, as shown in the simple policy below. This does not affect the server or REPL in the same way; only opa test currently seems to panic.

Example:
array-panic.rego

package test

a[0] := 1

Result:

panic: unreachable [recovered]
	panic: unreachable

goroutine 1 [running]:
github.com/open-policy-agent/opa/ast.(*Compiler).compile.func1()
	/opa-dev-dir/ast/compile.go:1353 +0x49
panic({0xfdee20, 0x1584700})
	/usr/local/go/src/runtime/panic.go:884 +0x212
github.com/open-policy-agent/opa/tester.ruleName(...)
	/opa-dev-dir/tester/runner.go:440
github.com/open-policy-agent/opa/tester.rewriteDuplicateTestNames(0xc000122140)
	/opa-dev-dir/tester/runner.go:406 +0x625
github.com/open-policy-agent/opa/ast.(*Compiler).runStageAfter(0x1039660?, {0x11c6238?, 0x11b879d?}, 0x13?)
	/opa-dev-dir/ast/compile.go:1346 +0xed
github.com/open-policy-agent/opa/ast.(*Compiler).compile(0xc000122140)
	/opa-dev-dir/ast/compile.go:1363 +0x1c9
github.com/open-policy-agent/opa/ast.(*Compiler).Compile(0xc000122140, 0xc0003301b0)
	/opa-dev-dir/ast/compile.go:450 +0x3c5
github.com/open-policy-agent/opa/tester.(*Runner).runTests(0xc0001f7050, {0x1590f18?, 0xc0004ba880}, {0x1586940, 0xc000330330}, 0x1, 0xc0004915b0)
	/opa-dev-dir/tester/runner.go:344 +0x631
github.com/open-policy-agent/opa/tester.(*Runner).RunTests(...)
	/opa-dev-dir/tester/runner.go:264
github.com/open-policy-agent/opa/cmd.runTests({0x1590f18, 0xc0004ba880}, {0x1586940, 0xc000330330}, 0xc0001f7050, {0x1589640, 0xc000715e48})
	/opa-dev-dir/cmd/test.go:303 +0x113
github.com/open-policy-agent/opa/cmd.opaTest({0xc000490d50, 0x1, 0x1})
	/opa-dev-dir/cmd/test.go:285 +0xce5
github.com/open-policy-agent/opa/cmd.glob..func5(0x1daf8a0?, {0xc000490d50?, 0x1?, 0x1?})
	/opa-dev-dir/cmd/test.go:147 +0x27
github.com/spf13/cobra.(*Command).execute(0x1daf8a0, {0xc000490d10, 0x1, 0x1})
	/opa-dev-dir/vendor/github.com/spf13/cobra/command.go:920 +0x847
github.com/spf13/cobra.(*Command).ExecuteC(0x1daf000)
	/opa-dev-dir/vendor/github.com/spf13/cobra/command.go:1044 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
	/opa-dev-dir/vendor/github.com/spf13/cobra/command.go:968
main.main()
	/opa-dev-dir/main.go:14 +0x25

Steps To Reproduce

  1. Create the file shown above.
  2. Run opa test array-panic.rego
  3. Observe the stack trace.
philipaconrad added a commit to philipaconrad/opa that referenced this issue Dec 21, 2022
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 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>
philipaconrad added a commit that referenced this issue Dec 21, 2022
This commit fixes a panic from a utility function in the `opa test`
codepath. After the ref-heads change in #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: #5496

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
philipaconrad added a commit to philipaconrad/opa that referenced this issue Dec 21, 2022
…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>
(cherry picked from commit a08934d)
philipaconrad added a commit that referenced this issue Dec 21, 2022
This commit fixes a panic from a utility function in the `opa test`
codepath. After the ref-heads change in #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: #5496

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
(cherry picked from commit a08934d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant