MCPcopy
hub / github.com/apache/casbin / TestImplicitRoleAPI

Function TestImplicitRoleAPI

rbac_api_test.go:310–327  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

308}
309
310func TestImplicitRoleAPI(t *testing.T) {
311 e, _ := NewEnforcer("examples/rbac_model.conf", "examples/rbac_with_hierarchy_policy.csv")
312
313 testGetPermissions(t, e, "alice", [][]string{{"alice", "data1", "read"}})
314 testGetPermissions(t, e, "bob", [][]string{{"bob", "data2", "write"}})
315
316 testGetImplicitRoles(t, e, "alice", []string{"admin", "data1_admin", "data2_admin"})
317 testGetImplicitRoles(t, e, "bob", []string{})
318
319 e, _ = NewEnforcer("examples/rbac_with_pattern_model.conf", "examples/rbac_with_pattern_policy.csv")
320
321 e.GetRoleManager().AddMatchingFunc("matcher", util.KeyMatch)
322 e.AddNamedMatchingFunc("g2", "matcher", util.KeyMatch)
323
324 // testGetImplicitRoles(t, e, "cathy", []string{"/book/1/2/3/4/5", "pen_admin", "/book/*", "book_group"})
325 testGetImplicitRoles(t, e, "cathy", []string{"/book/1/2/3/4/5", "pen_admin"})
326 testGetRoles(t, e, []string{"/book/1/2/3/4/5", "pen_admin"}, "cathy")
327}
328
329func testGetImplicitPermissions(t *testing.T, e *Enforcer, name string, res [][]string, domain ...string) {
330 t.Helper()

Callers

nothing calls this directly

Calls 7

GetRoleManagerMethod · 0.95
AddNamedMatchingFuncMethod · 0.95
NewEnforcerFunction · 0.85
testGetPermissionsFunction · 0.85
testGetImplicitRolesFunction · 0.85
testGetRolesFunction · 0.85
AddMatchingFuncMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…