(t *testing.T)
| 743 | } |
| 744 | |
| 745 | func 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 | |
| 772 | func TestEnforcerSetDetector(t *testing.T) { |
| 773 | // Test SetDetector() method |
nothing calls this directly
no test coverage detected
searching dependent graphs…