(t *testing.T)
| 62 | } |
| 63 | |
| 64 | func Test_StringRbac(t *testing.T) { |
| 65 | conf := ` |
| 66 | [request_definition] |
| 67 | r = sub, obj, act |
| 68 | |
| 69 | [policy_definition] |
| 70 | p = sub, obj, act |
| 71 | |
| 72 | [role_definition] |
| 73 | g = _ , _ |
| 74 | |
| 75 | [policy_effect] |
| 76 | e = some(where (p.eft == allow)) |
| 77 | |
| 78 | [matchers] |
| 79 | m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act |
| 80 | ` |
| 81 | line := ` |
| 82 | p, alice, data1, read |
| 83 | p, data_group_admin, data3, read |
| 84 | p, data_group_admin, data3, write |
| 85 | g, 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…