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

Function Test_StringRbac

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

Source from the content-addressed store, hash-verified

62}
63
64func Test_StringRbac(t *testing.T) {
65 conf := `
66[request_definition]
67r = sub, obj, act
68
69[policy_definition]
70p = sub, obj, act
71
72[role_definition]
73g = _ , _
74
75[policy_effect]
76e = some(where (p.eft == allow))
77
78[matchers]
79m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
80`
81 line := `
82p, alice, data1, read
83p, data_group_admin, data3, read
84p, data_group_admin, data3, write
85g, alice, data_group_admin
86`
87 a := NewAdapter(line)
88 m := model.NewModel()
89 err := m.LoadModelFromText(conf)
90 if err != nil {
91 t.Errorf("load model from text failed: %v", err.Error())
92 return
93 }
94 e, _ := casbin.NewEnforcer(m, a)
95 sub := "alice" // the user that wants to access a resource.
96 obj := "data1" // the resource that is going to be accessed.
97 act := "read" // the operation that the user performs on the resource.
98 if res, _ := e.Enforce(sub, obj, act); !res {
99 t.Error("unexpected enforce result")
100 }
101}

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…