refactor(xff): split into generic, echo, and fastly packages
Extract generic trusted proxy handling into xff/ (stdlib only), Echo framework adapter into xff/echo/, and slim xff/fastlyxff/ down to Fastly JSON loading. Key changes: - xff/ uses netip.Prefix for efficient IP matching - Fix XFF extraction to walk right-to-left per MDN spec - Remove echo dependency from core xff package - fastlyxff.New() now returns *xff.TrustedProxies
This commit is contained in:
31
xff/echo/echo_test.go
Normal file
31
xff/echo/echo_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package xffecho
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.ntppool.org/common/xff"
|
||||
)
|
||||
|
||||
func TestTrustOptions(t *testing.T) {
|
||||
tp, err := xff.NewFromCIDRs([]string{
|
||||
"192.0.2.0/24",
|
||||
"203.0.113.0/24",
|
||||
"2001:db8::/32",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
opts := TrustOptions(tp)
|
||||
if len(opts) != 3 {
|
||||
t.Errorf("expected 3 trust options, got %d", len(opts))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrustOptionsEmpty(t *testing.T) {
|
||||
tp := xff.New()
|
||||
opts := TrustOptions(tp)
|
||||
if len(opts) != 0 {
|
||||
t.Errorf("expected 0 trust options, got %d", len(opts))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user