MCPcopy Index your code
hub / github.com/apache/casbin / TestEnforcerRunDetections

Function TestEnforcerRunDetections

enforcer_test.go:745–770  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

743}
744
745func TestEnforcerRunDetections(t *testing.T) {
746 // Test explicit RunDetections() call
747 e, _ := NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
748
749 // Should not error on valid policy
750 err := e.RunDetections()
751 if err != nil {
752 t.Errorf("Expected no error when running detections on valid policy, but got: %v", err)
753 }
754
755 // Now add a cycle manually
756 _, _ = e.AddGroupingPolicy("alice", "data2_admin")
757 _, _ = e.AddGroupingPolicy("data2_admin", "super_admin")
758 _, _ = e.AddGroupingPolicy("super_admin", "alice")
759
760 // Should detect the cycle
761 err = e.RunDetections()
762 if err == nil {
763 t.Error("Expected cycle detection error, but got nil")
764 } else {
765 errMsg := err.Error()
766 if !strings.Contains(errMsg, "cycle detected") {
767 t.Errorf("Expected error message to contain 'cycle detected', got: %s", errMsg)
768 }
769 }
770}
771
772func TestEnforcerSetDetector(t *testing.T) {
773 // Test SetDetector() method

Callers

nothing calls this directly

Calls 4

RunDetectionsMethod · 0.95
AddGroupingPolicyMethod · 0.95
NewEnforcerFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…