55 "net/http/httptest"
66 "testing"
77
8- "github.com/casbin/casbin"
8+ "github.com/casbin/casbin/v2 "
99 "github.com/labstack/echo/v4"
1010)
1111
@@ -37,7 +37,7 @@ func testRequest(t *testing.T, ce *casbin.Enforcer, user string, path string, me
3737}
3838
3939func TestAuth (t * testing.T ) {
40- ce := casbin .NewEnforcer ("auth_model.conf" , "auth_policy.csv" )
40+ ce , _ := casbin .NewEnforcer ("auth_model.conf" , "auth_policy.csv" )
4141
4242 testRequest (t , ce , "alice" , "/dataset1/resource1" , echo .GET , 200 )
4343 testRequest (t , ce , "alice" , "/dataset1/resource1" , echo .POST , 200 )
@@ -46,7 +46,7 @@ func TestAuth(t *testing.T) {
4646}
4747
4848func TestPathWildcard (t * testing.T ) {
49- ce := casbin .NewEnforcer ("auth_model.conf" , "auth_policy.csv" )
49+ ce , _ := casbin .NewEnforcer ("auth_model.conf" , "auth_policy.csv" )
5050
5151 testRequest (t , ce , "bob" , "/dataset2/resource1" , "GET" , 200 )
5252 testRequest (t , ce , "bob" , "/dataset2/resource1" , "POST" , 200 )
@@ -64,7 +64,7 @@ func TestPathWildcard(t *testing.T) {
6464}
6565
6666func TestRBAC (t * testing.T ) {
67- ce := casbin .NewEnforcer ("auth_model.conf" , "auth_policy.csv" )
67+ ce , _ := casbin .NewEnforcer ("auth_model.conf" , "auth_policy.csv" )
6868
6969 // cathy can access all /dataset1/* resources via all methods because it has the dataset1_admin role.
7070 testRequest (t , ce , "cathy" , "/dataset1/item" , "GET" , 200 )
@@ -84,3 +84,8 @@ func TestRBAC(t *testing.T) {
8484 testRequest (t , ce , "cathy" , "/dataset2/item" , "POST" , 403 )
8585 testRequest (t , ce , "cathy" , "/dataset2/item" , "DELETE" , 403 )
8686}
87+
88+ func TestEnforceError (t * testing.T ) {
89+ ce , _ := casbin .NewEnforcer ("broken_auth_model.conf" , "auth_policy.csv" )
90+ testRequest (t , ce , "cathy" , "/dataset1/item" , "GET" , 500 )
91+ }
0 commit comments