(t *testing.T)
| 26 | ) |
| 27 | |
| 28 | func TestKeyMatchModelInMemory(t *testing.T) { |
| 29 | m := model.NewModel() |
| 30 | m.AddDef("r", "r", "sub, obj, act") |
| 31 | m.AddDef("p", "p", "sub, obj, act") |
| 32 | m.AddDef("e", "e", "some(where (p.eft == allow))") |
| 33 | m.AddDef("m", "m", "r.sub == p.sub && keyMatch(r.obj, p.obj) && regexMatch(r.act, p.act)") |
| 34 | |
| 35 | a := fileadapter.NewAdapter("examples/keymatch_policy.csv") |
| 36 | |
| 37 | e, _ := NewEnforcer(m, a) |
| 38 | |
| 39 | testEnforce(t, e, "alice", "/alice_data/resource1", "GET", true) |
| 40 | testEnforce(t, e, "alice", "/alice_data/resource1", "POST", true) |
| 41 | testEnforce(t, e, "alice", "/alice_data/resource2", "GET", true) |
| 42 | testEnforce(t, e, "alice", "/alice_data/resource2", "POST", false) |
| 43 | testEnforce(t, e, "alice", "/bob_data/resource1", "GET", false) |
| 44 | testEnforce(t, e, "alice", "/bob_data/resource1", "POST", false) |
| 45 | testEnforce(t, e, "alice", "/bob_data/resource2", "GET", false) |
| 46 | testEnforce(t, e, "alice", "/bob_data/resource2", "POST", false) |
| 47 | |
| 48 | testEnforce(t, e, "bob", "/alice_data/resource1", "GET", false) |
| 49 | testEnforce(t, e, "bob", "/alice_data/resource1", "POST", false) |
| 50 | testEnforce(t, e, "bob", "/alice_data/resource2", "GET", true) |
| 51 | testEnforce(t, e, "bob", "/alice_data/resource2", "POST", false) |
| 52 | testEnforce(t, e, "bob", "/bob_data/resource1", "GET", false) |
| 53 | testEnforce(t, e, "bob", "/bob_data/resource1", "POST", true) |
| 54 | testEnforce(t, e, "bob", "/bob_data/resource2", "GET", false) |
| 55 | testEnforce(t, e, "bob", "/bob_data/resource2", "POST", true) |
| 56 | |
| 57 | testEnforce(t, e, "cathy", "/cathy_data", "GET", true) |
| 58 | testEnforce(t, e, "cathy", "/cathy_data", "POST", true) |
| 59 | testEnforce(t, e, "cathy", "/cathy_data", "DELETE", false) |
| 60 | |
| 61 | e, _ = NewEnforcer(m) |
| 62 | _ = a.LoadPolicy(e.GetModel()) |
| 63 | |
| 64 | testEnforce(t, e, "alice", "/alice_data/resource1", "GET", true) |
| 65 | testEnforce(t, e, "alice", "/alice_data/resource1", "POST", true) |
| 66 | testEnforce(t, e, "alice", "/alice_data/resource2", "GET", true) |
| 67 | testEnforce(t, e, "alice", "/alice_data/resource2", "POST", false) |
| 68 | testEnforce(t, e, "alice", "/bob_data/resource1", "GET", false) |
| 69 | testEnforce(t, e, "alice", "/bob_data/resource1", "POST", false) |
| 70 | testEnforce(t, e, "alice", "/bob_data/resource2", "GET", false) |
| 71 | testEnforce(t, e, "alice", "/bob_data/resource2", "POST", false) |
| 72 | |
| 73 | testEnforce(t, e, "bob", "/alice_data/resource1", "GET", false) |
| 74 | testEnforce(t, e, "bob", "/alice_data/resource1", "POST", false) |
| 75 | testEnforce(t, e, "bob", "/alice_data/resource2", "GET", true) |
| 76 | testEnforce(t, e, "bob", "/alice_data/resource2", "POST", false) |
| 77 | testEnforce(t, e, "bob", "/bob_data/resource1", "GET", false) |
| 78 | testEnforce(t, e, "bob", "/bob_data/resource1", "POST", true) |
| 79 | testEnforce(t, e, "bob", "/bob_data/resource2", "GET", false) |
| 80 | testEnforce(t, e, "bob", "/bob_data/resource2", "POST", true) |
| 81 | |
| 82 | testEnforce(t, e, "cathy", "/cathy_data", "GET", true) |
| 83 | testEnforce(t, e, "cathy", "/cathy_data", "POST", true) |
| 84 | testEnforce(t, e, "cathy", "/cathy_data", "DELETE", false) |
| 85 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…