Skip to content

Commit 8e999bd

Browse files
committed
use the logger
1 parent 72502e5 commit 8e999bd

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

jail/jail.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ func DefaultOS(config Config) (Jailer, error) {
3434
default:
3535
return nil, fmt.Errorf("unsupported operating system: %s", runtime.GOOS)
3636
}
37-
}
37+
}

jail/linux_stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ import (
99
// NewLinuxJail is not available on non-Linux platforms
1010
func NewLinuxJail(_ Config) (Jailer, error) {
1111
return nil, fmt.Errorf("linux jail not supported on this platform")
12-
}
12+
}

jail/macos_stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ import "fmt"
77
// NewMacOSJail is not available on non-macOS platforms
88
func NewMacOSJail(_ Config) (Jailer, error) {
99
return nil, fmt.Errorf("macOS jail not supported on this platform")
10-
}
10+
}

rules/rules.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,14 @@ func (re *Engine) matches(r Rule, method, url string) bool {
429429
}
430430
}
431431
if !methodMatches {
432+
re.logger.Info("rule does not match", "reason", "method pattern mismatch", "rule", r.Raw, "method", method, "url", url)
432433
return false
433434
}
434435
}
435436

436437
parsedUrl, err := neturl.Parse(url)
437438
if err != nil {
439+
re.logger.Info("rule does not match", "reason", "invalid URL", "rule", r.Raw, "method", method, "url", url, "error", err)
438440
return false
439441
}
440442

@@ -448,13 +450,15 @@ func (re *Engine) matches(r Rule, method, url string) bool {
448450

449451
// If the host pattern is longer than the actual host, it's definitely not a match
450452
if len(r.HostPattern) > len(labels) {
453+
re.logger.Info("rule does not match", "reason", "host pattern too long", "rule", r.Raw, "method", method, "url", url, "pattern_length", len(r.HostPattern), "hostname_labels", len(labels))
451454
return false
452455
}
453456

454457
// Compare pattern with the end of labels (allowing subdomains)
455458
for i, lp := range r.HostPattern {
456459
labelIndex := len(labels) - len(r.HostPattern) + i
457460
if string(lp) != labels[labelIndex] && lp != "*" {
461+
re.logger.Info("rule does not match", "reason", "host pattern label mismatch", "rule", r.Raw, "method", method, "url", url, "expected", string(lp), "actual", labels[labelIndex])
458462
return false
459463
}
460464
}
@@ -465,16 +469,19 @@ func (re *Engine) matches(r Rule, method, url string) bool {
465469

466470
// If the path pattern is longer than the actual path, definitely not a match
467471
if len(r.PathPattern) > len(segments) {
472+
re.logger.Info("rule does not match", "reason", "path pattern too long", "rule", r.Raw, "method", method, "url", url, "pattern_length", len(r.PathPattern), "path_segments", len(segments))
468473
return false
469474
}
470475

471476
// Each segment in the pattern must be either as asterisk or match the actual path segment
472477
for i, sp := range r.PathPattern {
473478
if string(sp) != segments[i] && sp != "*" {
479+
re.logger.Info("rule does not match", "reason", "path pattern segment mismatch", "rule", r.Raw, "method", method, "url", url, "expected", string(sp), "actual", segments[i])
474480
return false
475481
}
476482
}
477483
}
478484

485+
re.logger.Info("rule matches", "reason", "all patterns matched", "rule", r.Raw, "method", method, "url", url)
479486
return true
480487
}

rules/rules_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ func TestParseAllowRule(t *testing.T) {
10631063
}
10641064

10651065
func TestEngineMatches(t *testing.T) {
1066-
logger := &slog.Logger{}
1066+
logger := slog.Default()
10671067
engine := NewRuleEngine(nil, logger)
10681068

10691069
tests := []struct {
@@ -1282,8 +1282,8 @@ func TestEngineMatches(t *testing.T) {
12821282

12831283
// Edge cases
12841284
{
1285-
name: "empty rule matches everything",
1286-
rule: Rule{},
1285+
name: "empty rule matches everything",
1286+
rule: Rule{},
12871287
method: "GET",
12881288
url: "https://example.com/api/users",
12891289
expected: true,

0 commit comments

Comments
 (0)