diff --git a/allowed_ips_test.go b/allowed_ips_test.go index a68f3ae..55884c3 100644 --- a/allowed_ips_test.go +++ b/allowed_ips_test.go @@ -34,6 +34,9 @@ func TestAllowedIps(t *testing.T) { if a.Empty() { t.Fatal("should not be empty") } + if expected := `[127.0.0.1/32, 192.168.0.1/32, 192.168.1.0/24]`; a.String() != expected { + t.Errorf("expected %s, got %s", expected, a.String()) + } allowed := []string{ "127.0.0.1", diff --git a/backend_server_test.go b/backend_server_test.go index 3c9f676..53d58f7 100644 --- a/backend_server_test.go +++ b/backend_server_test.go @@ -30,6 +30,7 @@ import ( "encoding/json" "fmt" "io" + "net" "net/http" "net/http/httptest" "net/textproto" @@ -1737,6 +1738,7 @@ func TestBackendServer_TurnCredentials(t *testing.T) { func TestBackendServer_StatsAllowedIps(t *testing.T) { CatchLogForTest(t) config := goconf.NewConfigFile() + config.AddOption("app", "trustedproxies", "1.2.3.4") config.AddOption("stats", "allowed_ips", "127.0.0.1, 192.168.0.1, 192.168.1.1/24") _, backend, _, _, _, _ := CreateBackendServerForTestFromConfig(t, config) @@ -1763,6 +1765,10 @@ func TestBackendServer_StatsAllowedIps(t *testing.T) { t.Errorf("should allow %s", addr) } + if host, _, err := net.SplitHostPort(addr); err == nil { + addr = host + } + r2 := &http.Request{ RemoteAddr: "1.2.3.4:12345", Header: http.Header{