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
32 lines
525 B
Go
32 lines
525 B
Go
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))
|
|
}
|
|
}
|