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

Function TestModifyPolicyAPI

management_api_test.go:202–281  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

200}
201
202func TestModifyPolicyAPI(t *testing.T) {
203 e, _ := NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
204
205 testGetPolicy(t, e, [][]string{
206 {"alice", "data1", "read"},
207 {"bob", "data2", "write"},
208 {"data2_admin", "data2", "read"},
209 {"data2_admin", "data2", "write"}})
210
211 _, _ = e.RemovePolicy("alice", "data1", "read")
212 _, _ = e.RemovePolicy("bob", "data2", "write")
213 _, _ = e.RemovePolicy("alice", "data1", "read")
214 _, _ = e.AddPolicy("eve", "data3", "read")
215 _, _ = e.AddPolicy("eve", "data3", "read")
216
217 rules := [][]string{
218 {"jack", "data4", "read"},
219 {"jack", "data4", "read"},
220 {"jack", "data4", "read"},
221 {"katy", "data4", "write"},
222 {"leyo", "data4", "read"},
223 {"katy", "data4", "write"},
224 {"katy", "data4", "write"},
225 {"ham", "data4", "write"},
226 }
227
228 _, _ = e.AddPolicies(rules)
229 _, _ = e.AddPolicies(rules)
230
231 testGetPolicy(t, e, [][]string{
232 {"data2_admin", "data2", "read"},
233 {"data2_admin", "data2", "write"},
234 {"eve", "data3", "read"},
235 {"jack", "data4", "read"},
236 {"katy", "data4", "write"},
237 {"leyo", "data4", "read"},
238 {"ham", "data4", "write"}})
239
240 _, _ = e.RemovePolicies(rules)
241 _, _ = e.RemovePolicies(rules)
242
243 namedPolicy := []string{"eve", "data3", "read"}
244 _, _ = e.RemoveNamedPolicy("p", namedPolicy)
245 _, _ = e.AddNamedPolicy("p", namedPolicy)
246
247 testGetPolicy(t, e, [][]string{
248 {"data2_admin", "data2", "read"},
249 {"data2_admin", "data2", "write"},
250 {"eve", "data3", "read"}})
251
252 _, _ = e.RemoveFilteredPolicy(1, "data2")
253
254 testGetPolicy(t, e, [][]string{{"eve", "data3", "read"}})
255
256 _, _ = e.UpdatePolicy([]string{"eve", "data3", "read"}, []string{"eve", "data3", "write"})
257
258 testGetPolicy(t, e, [][]string{{"eve", "data3", "write"}})
259

Callers

nothing calls this directly

Calls 15

RemovePolicyMethod · 0.95
AddPolicyMethod · 0.95
AddPoliciesMethod · 0.95
RemovePoliciesMethod · 0.95
RemoveNamedPolicyMethod · 0.95
AddNamedPolicyMethod · 0.95
RemoveFilteredPolicyMethod · 0.95
UpdatePolicyMethod · 0.95
UpdatePoliciesMethod · 0.95
ClearPolicyMethod · 0.95
AddPoliciesExMethod · 0.95
AddNamedPoliciesExMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…