Files
pixa/internal/imagerequest/sourceurl_internal_test.go
T
clawbot 7b6712538e
check / check (push) Canceled after 0s
Take the signature, the expiry and the URL scheme off the image request (closes #314)
The image request now holds only its source and its transform, exactly what
the variant key covers. The /v1/image/ handler checks the allowlist and
verifies the signature itself with Signer.Verify(req, sig, expires). Both
image handlers keep the URL's expiry as a local value for Cache-Control. The
image service holds no signer, allowlist or AllowHTTP, and ValidateRequest is
gone. The fetcher takes the source and builds its URL with Source.URL from its
own AllowHTTP, so no URL string is built and parsed again. chooseAutoFormat
returns the format it chooses instead of writing into the request. The signed
URL format and every route's answers are unchanged.

Model: opus-5-5
2026-10-26 13:49:12 +01:00

51 lines
895 B
Go

package imagerequest
import "testing"
func TestSource_URL_DefaultHTTPS(t *testing.T) {
t.Parallel()
source := Source{
Host: testHostCDN,
Path: testPathCat,
Query: "v=2",
}
got := source.URL(false).String()
want := "https://cdn.example.com/photos/cat.jpg?v=2"
if got != want {
t.Errorf("URL() = %q, want %q", got, want)
}
}
func TestSource_URL_AllowHTTP(t *testing.T) {
t.Parallel()
source := Source{
Host: "localhost:8080",
Path: testPathCat,
}
got := source.URL(true).String()
want := "http://localhost:8080/photos/cat.jpg"
if got != want {
t.Errorf("URL() = %q, want %q", got, want)
}
}
func TestSource_URL_AllowHTTPFalse(t *testing.T) {
t.Parallel()
source := Source{
Host: testHostCDN,
Path: "/img.jpg",
}
got := source.URL(false).String()
if got != "https://cdn.example.com/img.jpg" {
t.Errorf("URL() = %q, want https scheme", got)
}
}