package server import ( "io" "net/http" "net/http/httptest" "testing" ) // TestImageProxyRefusesSVG requests an image the upstream answers as SVG, // in its own format (orig) and resized as PNG, through pixa's router, // upstream fetcher and image processor. pixa does not accept SVG as a // source, so each request is answered 415, never with an image. func TestImageProxyRefusesSVG(t *testing.T) { t.Parallel() upstream := httptest.NewServer(http.HandlerFunc( func(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "image/svg+xml") _, _ = io.WriteString(w, ``) })) t.Cleanup(upstream.Close) s, _, _ := startImageProxy(t, upstream) for _, sizeFormat := range []string{"64x48.orig", "32x24.png"} { target := "/v1/image/" + upstreamHost + "/drawing.svg/" + sizeFormat rec := httptest.NewRecorder() s.ServeHTTP(rec, httptest.NewRequestWithContext( t.Context(), http.MethodGet, target, nil)) t.Logf("GET %s: %d, Content-Type %s, body %s", target, rec.Code, rec.Header().Get("Content-Type"), rec.Body.String()) if rec.Code != http.StatusUnsupportedMediaType { t.Errorf("GET %s status = %d, want %d", target, rec.Code, http.StatusUnsupportedMediaType) } } }