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

Function TestDomainPatternRole

rbac/default-role-manager/role_manager_test.go:267–295  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

265}
266
267func TestDomainPatternRole(t *testing.T) {
268 rm := NewRoleManager(10)
269 rm.AddDomainMatchingFunc("keyMatch2", util.KeyMatch2)
270
271 _ = rm.AddLink("u1", "g1", "domain1")
272 _ = rm.AddLink("u2", "g1", "domain2")
273 _ = rm.AddLink("u3", "g1", "*")
274 _ = rm.AddLink("u4", "g2", "domain3")
275 // Current role inheritance tree after deleting the links:
276 // domain1:g1 domain2:g1 domain3:g2
277 // / \ / \ |
278 // domain1:u1 *:g1 domain2:u2 domain3:u4
279 // |
280 // *:u3
281 testDomainRole(t, rm, "u1", "g1", "domain1", true)
282 testDomainRole(t, rm, "u2", "g1", "domain1", false)
283 testDomainRole(t, rm, "u2", "g1", "domain2", true)
284 testDomainRole(t, rm, "u3", "g1", "domain1", true)
285 testDomainRole(t, rm, "u3", "g1", "domain2", true)
286 testDomainRole(t, rm, "u1", "g2", "domain1", false)
287 testDomainRole(t, rm, "u4", "g2", "domain3", true)
288 testDomainRole(t, rm, "u3", "g2", "domain3", false)
289
290 testPrintRolesWithDomain(t, rm, "u3", "domain1", []string{"g1"})
291 testPrintRolesWithDomain(t, rm, "u1", "domain1", []string{"g1"})
292 testPrintRolesWithDomain(t, rm, "u3", "domain2", []string{"g1"})
293 testPrintRolesWithDomain(t, rm, "u1", "domain2", []string{})
294 testPrintRolesWithDomain(t, rm, "u4", "domain3", []string{"g2"})
295}
296
297func TestAllMatchingFunc(t *testing.T) {
298 rm := NewRoleManager(10)

Callers

nothing calls this directly

Calls 5

AddDomainMatchingFuncMethod · 0.95
AddLinkMethod · 0.95
testDomainRoleFunction · 0.85
testPrintRolesWithDomainFunction · 0.85
NewRoleManagerFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…