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

Function TestIEnforcerContext_BasicOperations

enforcer_context_test.go:23–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestIEnforcerContext_BasicOperations(t *testing.T) {
24 e, err := NewContextEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
25 if err != nil {
26 t.Fatalf("NewContextEnforcer failed: %v", err)
27 }
28
29 ctx := context.Background()
30
31 err = e.LoadPolicyCtx(ctx)
32 if err != nil {
33 t.Fatalf("LoadPolicyCtx failed: %v", err)
34 }
35
36 added, err := e.AddPolicyCtx(ctx, "eve", "data3", "read")
37 if err != nil {
38 t.Fatalf("AddPolicyCtx failed: %v", err)
39 }
40 if !added {
41 t.Error("AddPolicyCtx should return true for new policy")
42 }
43
44 removed, err := e.RemovePolicyCtx(ctx, "eve", "data3", "read")
45 if err != nil {
46 t.Fatalf("RemovePolicyCtx failed: %v", err)
47 }
48 if !removed {
49 t.Error("RemovePolicyCtx should return true for existing policy")
50 }
51
52 err = e.SavePolicyCtx(ctx)
53 if err != nil {
54 t.Fatalf("SavePolicyCtx failed: %v", err)
55 }
56}
57
58func TestIEnforcerContext_RBACOperations(t *testing.T) {
59 e, err := NewContextEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")

Callers

nothing calls this directly

Calls 6

LoadPolicyCtxMethod · 0.95
AddPolicyCtxMethod · 0.95
RemovePolicyCtxMethod · 0.95
SavePolicyCtxMethod · 0.95
NewContextEnforcerFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…