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()