Update tests.

This commit is contained in:
Joachim Bauch 2024-05-16 14:51:28 +02:00
parent aac4874e72
commit 4f8349d4c1
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 9 additions and 0 deletions

View file

@ -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",

View file

@ -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{