package httphelper_test import ( "net/http" "net/http/httptest" "testing" "github.com/stretchr/testify/assert" "github.com/bnema/gordon/internal/adapters/in/http/httphelper" ) func TestIsLocalhostRequest(t *testing.T) { tests := []struct { name string remoteAddr string want bool }{ {"ipv4 loopback", "127.0.0.1:12345", true}, {"ipv4 loopback other", "127.0.0.2:9000", true}, {"ipv6 loopback bracketed", "[::1]:12345", true}, {"external ipv4", "192.168.1.1:12345", false}, {"external ipv6", "[2001:db8::1]:12345", false}, {"empty", "", false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "/", nil) req.RemoteAddr = tt.remoteAddr got := httphelper.IsLocalhostRequest(req) assert.Equal(t, tt.want, got, "IsLocalhostRequest(%q)", tt.remoteAddr) }) } }