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

Function Test_KeyMatchRbac

persist/string-adapter/adapter_test.go:24–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func Test_KeyMatchRbac(t *testing.T) {
25 conf := `
26[request_definition]
27r = sub, obj, act
28
29[policy_definition]
30p = sub, obj, act
31
32[role_definition]
33g = _ , _
34
35[policy_effect]
36e = some(where (p.eft == allow))
37
38[matchers]
39m = g(r.sub, p.sub) && keyMatch(r.obj, p.obj) && regexMatch(r.act, p.act)
40`
41 line := `
42p, alice, /alice_data/*, (GET)|(POST)
43p, alice, /alice_data/resource1, POST
44p, data_group_admin, /admin/*, POST
45p, data_group_admin, /bob_data/*, POST
46g, alice, data_group_admin
47`
48 a := NewAdapter(line)
49 m := model.NewModel()
50 err := m.LoadModelFromText(conf)
51 if err != nil {
52 t.Errorf("load model from text failed: %v", err.Error())
53 return
54 }
55 e, _ := casbin.NewEnforcer(m, a)
56 sub := "alice"
57 obj := "/alice_data/login"
58 act := "POST"
59 if res, _ := e.Enforce(sub, obj, act); !res {
60 t.Error("unexpected enforce result")
61 }
62}
63
64func Test_StringRbac(t *testing.T) {
65 conf := `

Callers

nothing calls this directly

Calls 5

LoadModelFromTextMethod · 0.95
EnforceMethod · 0.95
NewModelFunction · 0.92
NewAdapterFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…