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

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
2 participants
@cdennison
Copy link

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):
https://github.com/casbin/casbin/blob/master/enforcer.go#L93

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:
https://github.com/casbin/casbin/blob/master/enforcer.go#L322

fmt.Printf("%v\n",parameters)
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 -test.run ^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]:
testing.tRunner.func1(0xc4200aa0f0)
	/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
github.com/casbin/casbin.(*Enforcer).Enforce(0xc42007e190, 0xc420055ea8, 0x3, 0x3, 0xc420055ea0)
	/Users/dennch3/go/thingspace/go/src/github.com/casbin/casbin/enforcer.go:324 +0x71f
github.com/casbin/casbin.testEnforce(0xc4200aa0f0, 0xc42007e190, 0x11d2358, 0x5, 0x1191b60, 0x11f33c0, 0x11d1fe2, 0x3, 0x1073401)
	/Users/dennch3/go/thingspace/go/src/github.com/casbin/casbin/model_test.go:26 +0x144
github.com/casbin/casbin.TestInitEmpty(0xc4200aa0f0)
	/Users/dennch3/go/thingspace/go/src/github.com/casbin/casbin/enforcer_test.go:402 +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	github.com/casbin/casbin	0.833s
@hsluoyz

This comment has been minimized.

Copy link
Member

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

@hsluoyz

This comment has been minimized.

Copy link
Member

commented Dec 13, 2017

Suppose this can be closed now.

@hsluoyz hsluoyz closed this Dec 13, 2017

@cdennison

This comment has been minimized.

Copy link
Author

commented Dec 18, 2017

@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.

@hsluoyz

This comment has been minimized.

Copy link
Member

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
You can’t perform that action at this time.