package config import ( "net" "testing" ) func TestIsTrustedProxy(t *testing.T) { cfg := &Config{} networks, err := parseCIDRs("10.0.0.0/8,127.0.0.1") if err != nil { t.Fatal(err) } cfg.TrustedProxies = networks if !cfg.IsTrustedProxy(net.ParseIP("10.1.2.3")) { t.Fatal("expected 10.1.2.3 trusted") } if !cfg.IsTrustedProxy(net.ParseIP("127.0.0.1")) { t.Fatal("expected 127.0.0.1 trusted") } if cfg.IsTrustedProxy(net.ParseIP("192.168.1.1")) { t.Fatal("expected 192.168.1.1 untrusted") } }