From b71f2958db319e8bdd99606607201e2fcabdd6c0 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 15 Oct 2026 04:54:40 +0000 Subject: [PATCH] Test that an unbracketed IPv6 host with a port needs a signature (part of #246) With 2001:db8::1 allowlisted, Go's URL parser, which the fetcher uses, reads 2001:db8::1:8443 as 2001:db8::1 with port 8443, and 2001:db8::1: as 2001:db8::1 with an empty port. Both must need a signature. The test fails until the port check reads the port as the parsed URL does. Model: opus-5-5 --- internal/imgcache/service_internal_test.go | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/internal/imgcache/service_internal_test.go b/internal/imgcache/service_internal_test.go index 39c7bf9..e4bbb30 100644 --- a/internal/imgcache/service_internal_test.go +++ b/internal/imgcache/service_internal_test.go @@ -301,6 +301,46 @@ func TestService_ValidateRequest_HostWithPortNeedsSignature(t *testing.T) { } } +// TestService_ValidateRequest_UnbracketedIPv6PortNeedsSignature verifies that +// an allowlisted IPv6 address written without brackets and followed by a +// port, or by a colon with no port, needs a signature. Go's URL parser, which +// the fetcher uses, reads 2001:db8::1:8443 as the host 2001:db8::1 with the +// port 8443. +func TestService_ValidateRequest_UnbracketedIPv6PortNeedsSignature( + t *testing.T, +) { + t.Parallel() + + svc, _ := SetupTestService(t, + WithSigningKey(testSigningKey), + WithAllowlist("2001:db8::1"), + ) + + for _, host := range []string{"2001:db8::1:8443", "2001:db8::1:"} { + t.Run(host, func(t *testing.T) { + t.Parallel() + + req := &ImageRequest{ + SourceHost: host, + SourcePath: testPathCat, + Size: Size{Width: 50, Height: 50}, + Format: FormatJPEG, + Quality: 85, + FitMode: FitCover, + } + + err := svc.ValidateRequest(req) + t.Logf("ValidateRequest() for host %q with no signature: %v", + host, err) + + if err == nil { + t.Errorf("host %q served without a signature, want refused", + host) + } + }) + } +} + func TestService_Get_InvalidFile(t *testing.T) { t.Parallel()