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

Function TestNotUsedRBACModelInMemory

enforcer_test.go:188–209  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

186}
187
188func TestNotUsedRBACModelInMemory(t *testing.T) {
189 m := model.NewModel()
190 m.AddDef("r", "r", "sub, obj, act")
191 m.AddDef("p", "p", "sub, obj, act")
192 m.AddDef("g", "g", "_, _")
193 m.AddDef("e", "e", "some(where (p.eft == allow))")
194 m.AddDef("m", "m", "g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act")
195
196 e, _ := NewEnforcer(m)
197
198 _, _ = e.AddPermissionForUser("alice", "data1", "read")
199 _, _ = e.AddPermissionForUser("bob", "data2", "write")
200
201 testEnforce(t, e, "alice", "data1", "read", true)
202 testEnforce(t, e, "alice", "data1", "write", false)
203 testEnforce(t, e, "alice", "data2", "read", false)
204 testEnforce(t, e, "alice", "data2", "write", false)
205 testEnforce(t, e, "bob", "data1", "read", false)
206 testEnforce(t, e, "bob", "data1", "write", false)
207 testEnforce(t, e, "bob", "data2", "read", false)
208 testEnforce(t, e, "bob", "data2", "write", true)
209}
210
211func TestMatcherUsingInOperator(t *testing.T) {
212 // From file config

Callers

nothing calls this directly

Calls 5

AddDefMethod · 0.95
AddPermissionForUserMethod · 0.95
NewModelFunction · 0.92
NewEnforcerFunction · 0.85
testEnforceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…