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

Adding tests and showing unexplained panic #56

wants to merge 1 commit into from


Copy link

@cdennison cdennison commented Dec 8, 2017

I've been testing getters/setters and getting a panic. I'm specifically trying to test this line (test is expected to fail):

You can see the issue by running this code. What's strange is that when I look at the expression.Evaluate() - the parameters being passed are the same:

result, err := expression.Evaluate(parameters)
//map[p_act:GET r_sub:alice r_obj:/alice_data/resource1 p_sub:alice r_act:GET p_obj:/alice_data/*]
go test -test.v ^TestInitEmpty$
=== RUN   TestInitEmpty
2017/12/08 16:07:43 [Policy:]
2017/12/08 16:07:43 [p :  sub, obj, act :  [[alice /alice_data/* GET] [alice /alice_data/resource1 POST] [bob /alice_data/resource2 GET] [bob /bob_data/* POST] [cathy /cathy_data (GET)|(POST)]]]
map[r_sub:alice p_sub:alice r_obj:/alice_data/resource1 r_act:GET p_obj:/alice_data/* p_act:GET]
--- FAIL: TestInitEmpty (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x114c2ef]

goroutine 5 [running]:
	/usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:711 +0x2d2
panic(0x11a3720, 0x12cae00)
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491 +0x283*Enforcer).Enforce(0xc42007e190, 0xc420055ea8, 0x3, 0x3, 0xc420055ea0)
	/Users/dennch3/go/thingspace/go/src/ +0x71f, 0xc42007e190, 0x11d2358, 0x5, 0x1191b60, 0x11f33c0, 0x11d1fe2, 0x3, 0x1073401)
	/Users/dennch3/go/thingspace/go/src/ +0x144
	/Users/dennch3/go/thingspace/go/src/ +0x267
testing.tRunner(0xc4200aa0f0, 0x11dd478)
	/usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
	/usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:789 +0x2de
exit status 2
FAIL	0.833s

Copy link

hsluoyz commented Dec 9, 2017

Hi. Thanks for pointing this out. I found this is a bug in Enforcer.SetModel(). The matcher functions such as keyMatch and regexMatch are not loaded when you initialize the model via Enforcer.SetModel(). I have fixed it in: 9bb178c

Copy link

hsluoyz commented Dec 13, 2017

Suppose this can be closed now.

@hsluoyz hsluoyz closed this Dec 13, 2017
Copy link

@hsluoyz - sorry for not getting back to you sooner - do you want to add the test cases from my PR? I can resubmit to show that they are now passing.

Copy link

hsluoyz commented Dec 18, 2017

I think you can resubmit these tests in a new PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants