Skip to content

Commit 4e2a4d3

Browse files
f0sselclaude
andcommitted
Rename EvaluateWithRule to Evaluate and fix test compatibility
- Rename RuleEngine.EvaluateWithRule() to Evaluate() for simpler API - Remove old boolean-only Evaluate() method - Update proxy.go to use renamed Evaluate() method - Fix rules tests to work with EvaluationResult struct - Clean up formatting and remove extra blank lines - All tests pass with unified evaluation method 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7be8449 commit 4e2a4d3

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

proxy/proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (p *ProxyServer) Stop() error {
106106
// handleHTTP handles regular HTTP requests
107107
func (p *ProxyServer) handleHTTP(w http.ResponseWriter, r *http.Request) {
108108
// Check if request should be allowed
109-
result := p.ruleEngine.EvaluateWithRule(r.Method, r.URL.String())
109+
result := p.ruleEngine.Evaluate(r.Method, r.URL.String())
110110

111111
// Audit the request
112112
auditReq := audit.HTTPRequestToAuditRequest(r)
@@ -132,7 +132,7 @@ func (p *ProxyServer) handleHTTPS(w http.ResponseWriter, r *http.Request) {
132132
}
133133

134134
// Check if request should be allowed
135-
result := p.ruleEngine.EvaluateWithRule(r.Method, fullURL)
135+
result := p.ruleEngine.Evaluate(r.Method, fullURL)
136136

137137
// Audit the request
138138
auditReq := &audit.Request{

rules/rules.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import (
66
"strings"
77
)
88

9-
109
// Rule represents an allow rule with optional HTTP method restrictions
1110
type Rule struct {
1211
Pattern string // wildcard pattern for matching
1312
Methods map[string]bool // nil means all methods allowed
1413
Raw string // rule string for logging
1514
}
1615

17-
1816
// Matches checks if the rule matches the given method and URL using wildcard patterns
1917
func (r *Rule) Matches(method, url string) bool {
2018
// Check method if specified
@@ -127,21 +125,8 @@ type EvaluationResult struct {
127125
Rule string // The rule that matched (if any)
128126
}
129127

130-
// Evaluate evaluates a request against all allow rules and returns true if allowed
131-
func (re *RuleEngine) Evaluate(method, url string) bool {
132-
// Check if any allow rule matches
133-
for _, rule := range re.rules {
134-
if rule.Matches(method, url) {
135-
return true
136-
}
137-
}
138-
139-
// Default deny if no allow rules match
140-
return false
141-
}
142-
143-
// EvaluateWithRule evaluates a request and returns both result and matching rule
144-
func (re *RuleEngine) EvaluateWithRule(method, url string) EvaluationResult {
128+
// Evaluate evaluates a request and returns both result and matching rule
129+
func (re *RuleEngine) Evaluate(method, url string) EvaluationResult {
145130
// Check if any allow rule matches
146131
for _, rule := range re.rules {
147132
if rule.Matches(method, url) {

rules/rules_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestWildcardMatch(t *testing.T) {
157157
// Basic exact matches
158158
{"exact match", "github.com", "github.com", true},
159159
{"no match", "github.com", "gitlab.com", false},
160-
160+
161161
// Wildcard * tests
162162
{"star matches all", "*", "anything.com", true},
163163
{"star matches empty", "*", "", true},
@@ -251,8 +251,8 @@ func TestRuleEngine(t *testing.T) {
251251
for _, tt := range tests {
252252
t.Run(tt.name, func(t *testing.T) {
253253
result := engine.Evaluate(tt.method, tt.url)
254-
if result != tt.expected {
255-
t.Errorf("expected %v, got %v", tt.expected, result)
254+
if result.Allowed != tt.expected {
255+
t.Errorf("expected %v, got %v", tt.expected, result.Allowed)
256256
}
257257
})
258258
}
@@ -287,9 +287,9 @@ func TestRuleEngineWildcardRules(t *testing.T) {
287287
for _, tt := range tests {
288288
t.Run(tt.name, func(t *testing.T) {
289289
result := engine.Evaluate(tt.method, tt.url)
290-
if result != tt.expected {
291-
t.Errorf("expected %v, got %v", tt.expected, result)
290+
if result.Allowed != tt.expected {
291+
t.Errorf("expected %v, got %v", tt.expected, result.Allowed)
292292
}
293293
})
294294
}
295-
}
295+
}

0 commit comments

Comments
 (0)