2021-04-26 13:52:50 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-09-30 18:00:28 +02:00
|
|
|
"fmt"
|
2022-10-28 17:15:13 +02:00
|
|
|
"io"
|
2021-04-26 13:52:50 +02:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2021-09-07 15:04:33 +02:00
|
|
|
"regexp"
|
2021-09-30 18:00:28 +02:00
|
|
|
"strings"
|
2021-04-26 13:52:50 +02:00
|
|
|
"testing"
|
2023-05-03 17:21:46 +02:00
|
|
|
"time"
|
2021-04-26 13:52:50 +02:00
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2021-09-30 16:23:30 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/config"
|
|
|
|
"github.com/imgproxy/imgproxy/v3/config/configurators"
|
2021-09-30 18:00:28 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/etag"
|
2021-09-30 16:23:30 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/imagedata"
|
|
|
|
"github.com/imgproxy/imgproxy/v3/imagemeta"
|
|
|
|
"github.com/imgproxy/imgproxy/v3/imagetype"
|
2021-09-30 18:00:28 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/options"
|
2021-09-30 16:23:30 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/router"
|
2022-06-10 14:07:09 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/svg"
|
2021-09-30 16:23:30 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/vips"
|
2021-04-26 13:52:50 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type ProcessingHandlerTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
router *router.Router
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) SetupSuite() {
|
|
|
|
config.Reset()
|
|
|
|
|
|
|
|
wd, err := os.Getwd()
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().NoError(err)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
2024-04-30 15:51:02 +02:00
|
|
|
s.T().Setenv("IMGPROXY_LOCAL_FILESYSTEM_ROOT", filepath.Join(wd, "/testdata"))
|
|
|
|
s.T().Setenv("IMGPROXY_CLIENT_KEEP_ALIVE_TIMEOUT", "0")
|
2021-04-26 13:52:50 +02:00
|
|
|
|
2022-07-18 15:48:50 +02:00
|
|
|
err = initialize()
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().NoError(err)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
2022-10-28 17:15:13 +02:00
|
|
|
logrus.SetOutput(io.Discard)
|
2022-04-07 10:14:44 +02:00
|
|
|
|
2021-04-26 13:52:50 +02:00
|
|
|
s.router = buildRouter()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TeardownSuite() {
|
|
|
|
shutdown()
|
|
|
|
logrus.SetOutput(os.Stdout)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) SetupTest() {
|
|
|
|
// We don't need config.LocalFileSystemRoot anymore as it is used
|
|
|
|
// only during initialization
|
|
|
|
config.Reset()
|
2023-03-22 19:25:51 +02:00
|
|
|
config.AllowLoopbackSourceAddresses = true
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) send(path string, header ...http.Header) *httptest.ResponseRecorder {
|
|
|
|
req := httptest.NewRequest(http.MethodGet, path, nil)
|
|
|
|
rw := httptest.NewRecorder()
|
|
|
|
|
|
|
|
if len(header) > 0 {
|
|
|
|
req.Header = header[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
s.router.ServeHTTP(rw, req)
|
|
|
|
|
|
|
|
return rw
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) readTestFile(name string) []byte {
|
|
|
|
wd, err := os.Getwd()
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().NoError(err)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
2022-10-28 17:15:13 +02:00
|
|
|
data, err := os.ReadFile(filepath.Join(wd, "testdata", name))
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().NoError(err)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) readBody(res *http.Response) []byte {
|
2022-10-28 17:15:13 +02:00
|
|
|
data, err := io.ReadAll(res.Body)
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().NoError(err)
|
2021-04-26 13:52:50 +02:00
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) sampleETagData(imgETag string) (string, *imagedata.ImageData, string) {
|
|
|
|
poStr := "rs:fill:4:4"
|
|
|
|
|
|
|
|
po := options.NewProcessingOptions()
|
|
|
|
po.ResizingType = options.ResizeFill
|
|
|
|
po.Width = 4
|
|
|
|
po.Height = 4
|
|
|
|
|
|
|
|
imgdata := imagedata.ImageData{
|
|
|
|
Type: imagetype.PNG,
|
|
|
|
Data: s.readTestFile("test1.png"),
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(imgETag) != 0 {
|
|
|
|
imgdata.Headers = map[string]string{"ETag": imgETag}
|
|
|
|
}
|
|
|
|
|
|
|
|
var h etag.Handler
|
|
|
|
|
|
|
|
h.SetActualProcessingOptions(po)
|
|
|
|
h.SetActualImageData(&imgdata)
|
|
|
|
return poStr, &imgdata, h.GenerateActualETag()
|
|
|
|
}
|
|
|
|
|
2021-04-26 13:52:50 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestRequest() {
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Equal("image/png", res.Header.Get("Content-Type"))
|
2021-04-26 13:52:50 +02:00
|
|
|
|
|
|
|
meta, err := imagemeta.DecodeMeta(res.Body)
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(imagetype.PNG, meta.Format())
|
|
|
|
s.Require().Equal(4, meta.Width())
|
|
|
|
s.Require().Equal(4, meta.Height())
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestSignatureValidationFailure() {
|
|
|
|
config.Keys = [][]byte{[]byte("test-key")}
|
|
|
|
config.Salts = [][]byte{[]byte("test-salt")}
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(403, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestSignatureValidationSuccess() {
|
|
|
|
config.Keys = [][]byte{[]byte("test-key")}
|
|
|
|
config.Salts = [][]byte{[]byte("test-salt")}
|
|
|
|
|
|
|
|
rw := s.send("/My9d3xq_PYpVHsPrCyww0Kh1w5KZeZhIlWhsa4az1TI/rs:fill:4:4/plain/local:///test1.png")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
2021-09-07 15:04:33 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestSourceValidation() {
|
|
|
|
imagedata.RedirectAllRequestsTo("local:///test1.png")
|
|
|
|
defer imagedata.StopRedirectingRequests()
|
|
|
|
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
allowedSources []string
|
|
|
|
requestPath string
|
|
|
|
expectedError bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "match http URL without wildcard",
|
|
|
|
allowedSources: []string{"local://", "http://images.dev/"},
|
|
|
|
requestPath: "/unsafe/plain/http://images.dev/lorem/ipsum.jpg",
|
|
|
|
expectedError: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "match http URL with wildcard in hostname single level",
|
|
|
|
allowedSources: []string{"local://", "http://*.mycdn.dev/"},
|
|
|
|
requestPath: "/unsafe/plain/http://a-1.mycdn.dev/lorem/ipsum.jpg",
|
|
|
|
expectedError: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "match http URL with wildcard in hostname multiple levels",
|
|
|
|
allowedSources: []string{"local://", "http://*.mycdn.dev/"},
|
|
|
|
requestPath: "/unsafe/plain/http://a-1.b-2.mycdn.dev/lorem/ipsum.jpg",
|
|
|
|
expectedError: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no match s3 URL with allowed local and http URLs",
|
|
|
|
allowedSources: []string{"local://", "http://images.dev/"},
|
|
|
|
requestPath: "/unsafe/plain/s3://images/lorem/ipsum.jpg",
|
|
|
|
expectedError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no match http URL with wildcard in hostname including slash",
|
|
|
|
allowedSources: []string{"local://", "http://*.mycdn.dev/"},
|
|
|
|
requestPath: "/unsafe/plain/http://other.dev/.mycdn.dev/lorem/ipsum.jpg",
|
|
|
|
expectedError: true,
|
|
|
|
},
|
|
|
|
}
|
2021-04-26 13:52:50 +02:00
|
|
|
|
2021-09-07 15:04:33 +02:00
|
|
|
for _, tc := range tt {
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Run(tc.name, func() {
|
2021-09-07 15:04:33 +02:00
|
|
|
exps := make([]*regexp.Regexp, len(tc.allowedSources))
|
|
|
|
for i, pattern := range tc.allowedSources {
|
|
|
|
exps[i] = configurators.RegexpFromPattern(pattern)
|
|
|
|
}
|
|
|
|
config.AllowedSources = exps
|
|
|
|
|
|
|
|
rw := s.send(tc.requestPath)
|
|
|
|
res := rw.Result()
|
|
|
|
|
|
|
|
if tc.expectedError {
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(404, res.StatusCode)
|
2021-09-07 15:04:33 +02:00
|
|
|
} else {
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2021-09-07 15:04:33 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
2023-03-22 19:25:51 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestSourceNetworkValidation() {
|
|
|
|
data := s.readTestFile("test1.png")
|
|
|
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
rw.WriteHeader(200)
|
|
|
|
rw.Write(data)
|
|
|
|
}))
|
|
|
|
defer server.Close()
|
|
|
|
|
|
|
|
var rw *httptest.ResponseRecorder
|
|
|
|
|
|
|
|
u := fmt.Sprintf("/unsafe/rs:fill:4:4/plain/%s/test1.png", server.URL)
|
|
|
|
fmt.Println(u)
|
|
|
|
|
|
|
|
rw = s.send(u)
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, rw.Result().StatusCode)
|
2023-03-22 19:25:51 +02:00
|
|
|
|
|
|
|
config.AllowLoopbackSourceAddresses = false
|
|
|
|
rw = s.send(u)
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(404, rw.Result().StatusCode)
|
2023-03-22 19:25:51 +02:00
|
|
|
}
|
|
|
|
|
2021-04-26 13:52:50 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestSourceFormatNotSupported() {
|
|
|
|
vips.DisableLoadSupport(imagetype.PNG)
|
|
|
|
defer vips.ResetLoadSupport()
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(422, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestResultingFormatNotSupported() {
|
|
|
|
vips.DisableSaveSupport(imagetype.PNG)
|
|
|
|
defer vips.ResetSaveSupport()
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@png")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(422, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestSkipProcessingConfig() {
|
|
|
|
config.SkipProcessingFormats = []imagetype.Type{imagetype.PNG}
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
|
|
|
actual := s.readBody(res)
|
|
|
|
expected := s.readTestFile("test1.png")
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().True(bytes.Equal(expected, actual))
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestSkipProcessingPO() {
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/skp:png/plain/local:///test1.png")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
|
|
|
actual := s.readBody(res)
|
|
|
|
expected := s.readTestFile("test1.png")
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().True(bytes.Equal(expected, actual))
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestSkipProcessingSameFormat() {
|
|
|
|
config.SkipProcessingFormats = []imagetype.Type{imagetype.PNG}
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@png")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
|
|
|
actual := s.readBody(res)
|
|
|
|
expected := s.readTestFile("test1.png")
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().True(bytes.Equal(expected, actual))
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestSkipProcessingDifferentFormat() {
|
|
|
|
config.SkipProcessingFormats = []imagetype.Type{imagetype.PNG}
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@jpg")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
|
|
|
actual := s.readBody(res)
|
|
|
|
expected := s.readTestFile("test1.png")
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().False(bytes.Equal(expected, actual))
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestSkipProcessingSVG() {
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.svg")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
|
|
|
actual := s.readBody(res)
|
2023-06-22 13:22:10 +02:00
|
|
|
expected, err := svg.Sanitize(&imagedata.ImageData{Data: s.readTestFile("test1.svg")})
|
2022-06-10 14:07:09 +02:00
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().NoError(err)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().True(bytes.Equal(expected.Data, actual))
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestNotSkipProcessingSVGToJPG() {
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.svg@jpg")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
|
|
|
|
actual := s.readBody(res)
|
|
|
|
expected := s.readTestFile("test1.svg")
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().False(bytes.Equal(expected, actual))
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestErrorSavingToSVG() {
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@svg")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(422, res.StatusCode)
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
2023-12-04 19:18:01 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughCacheControl() {
|
2021-04-26 13:52:50 +02:00
|
|
|
config.CacheControlPassthrough = true
|
|
|
|
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
2023-12-04 19:18:01 +02:00
|
|
|
rw.Header().Set("Cache-Control", "max-age=1234, public")
|
|
|
|
rw.Header().Set("Expires", time.Now().Add(time.Hour).UTC().Format(http.TimeFormat))
|
2021-04-26 13:52:50 +02:00
|
|
|
rw.WriteHeader(200)
|
2021-09-29 12:23:54 +02:00
|
|
|
rw.Write(s.readTestFile("test1.png"))
|
2021-04-26 13:52:50 +02:00
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal("max-age=1234, public", res.Header.Get("Cache-Control"))
|
|
|
|
s.Require().Empty(res.Header.Get("Expires"))
|
2023-12-04 19:18:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughExpires() {
|
|
|
|
config.CacheControlPassthrough = true
|
|
|
|
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
rw.Header().Set("Expires", time.Now().Add(1239*time.Second).UTC().Format(http.TimeFormat))
|
|
|
|
rw.WriteHeader(200)
|
|
|
|
rw.Write(s.readTestFile("test1.png"))
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
|
|
|
|
res := rw.Result()
|
|
|
|
|
|
|
|
// Use regex to allow some delay
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Regexp(regexp.MustCompile("max-age=123[0-9], public"), res.Header.Get("Cache-Control"))
|
|
|
|
s.Require().Empty(res.Header.Get("Expires"))
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughDisabled() {
|
|
|
|
config.CacheControlPassthrough = false
|
|
|
|
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
2023-12-04 19:18:01 +02:00
|
|
|
rw.Header().Set("Cache-Control", "max-age=1234, public")
|
|
|
|
rw.Header().Set("Expires", time.Now().Add(time.Hour).UTC().Format(http.TimeFormat))
|
2021-04-26 13:52:50 +02:00
|
|
|
rw.WriteHeader(200)
|
2021-09-29 12:23:54 +02:00
|
|
|
rw.Write(s.readTestFile("test1.png"))
|
2021-04-26 13:52:50 +02:00
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().NotEqual("max-age=1234, public", res.Header.Get("Cache-Control"))
|
|
|
|
s.Require().Empty(res.Header.Get("Expires"))
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 12:23:54 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestETagDisabled() {
|
|
|
|
config.ETagEnabled = false
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Empty(res.Header.Get("ETag"))
|
2021-09-29 12:23:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestETagReqNoIfNotModified() {
|
|
|
|
config.ETagEnabled = true
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
poStr, imgdata, etag := s.sampleETagData("loremipsumdolor")
|
|
|
|
|
2021-09-29 12:23:54 +02:00
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Empty(r.Header.Get("If-None-Match"))
|
2021-09-29 12:23:54 +02:00
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
rw.Header().Set("ETag", imgdata.Headers["ETag"])
|
2021-09-29 12:23:54 +02:00
|
|
|
rw.WriteHeader(200)
|
|
|
|
rw.Write(s.readTestFile("test1.png"))
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL))
|
2021-09-29 12:23:54 +02:00
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Equal(etag, res.Header.Get("ETag"))
|
2021-09-29 12:23:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestETagDataNoIfNotModified() {
|
|
|
|
config.ETagEnabled = true
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
poStr, imgdata, etag := s.sampleETagData("")
|
|
|
|
|
2021-09-29 12:23:54 +02:00
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Empty(r.Header.Get("If-None-Match"))
|
2021-09-29 12:23:54 +02:00
|
|
|
|
|
|
|
rw.WriteHeader(200)
|
2021-09-30 18:00:28 +02:00
|
|
|
rw.Write(imgdata.Data)
|
2021-09-29 12:23:54 +02:00
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL))
|
2021-09-29 12:23:54 +02:00
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Equal(etag, res.Header.Get("ETag"))
|
2021-09-29 12:23:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestETagReqMatch() {
|
|
|
|
config.ETagEnabled = true
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
poStr, imgdata, etag := s.sampleETagData(`"loremipsumdolor"`)
|
|
|
|
|
2021-09-29 12:23:54 +02:00
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(imgdata.Headers["ETag"], r.Header.Get("If-None-Match"))
|
2021-09-29 12:23:54 +02:00
|
|
|
|
|
|
|
rw.WriteHeader(304)
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
header := make(http.Header)
|
|
|
|
header.Set("If-None-Match", etag)
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
|
2021-09-29 12:23:54 +02:00
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(304, res.StatusCode)
|
|
|
|
s.Require().Equal(etag, res.Header.Get("ETag"))
|
2021-09-29 12:23:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestETagDataMatch() {
|
|
|
|
config.ETagEnabled = true
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
poStr, imgdata, etag := s.sampleETagData("")
|
|
|
|
|
2021-09-29 12:23:54 +02:00
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Empty(r.Header.Get("If-None-Match"))
|
2021-09-29 12:23:54 +02:00
|
|
|
|
|
|
|
rw.WriteHeader(200)
|
2021-09-30 18:00:28 +02:00
|
|
|
rw.Write(imgdata.Data)
|
2021-09-29 12:23:54 +02:00
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
header := make(http.Header)
|
|
|
|
header.Set("If-None-Match", etag)
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
|
2021-09-29 12:23:54 +02:00
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(304, res.StatusCode)
|
|
|
|
s.Require().Equal(etag, res.Header.Get("ETag"))
|
2021-09-29 12:23:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestETagReqNotMatch() {
|
|
|
|
config.ETagEnabled = true
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
poStr, imgdata, actualETag := s.sampleETagData(`"loremipsumdolor"`)
|
|
|
|
_, _, expectedETag := s.sampleETagData(`"loremipsum"`)
|
|
|
|
|
2021-09-29 12:23:54 +02:00
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(`"loremipsum"`, r.Header.Get("If-None-Match"))
|
2021-09-29 12:23:54 +02:00
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
rw.Header().Set("ETag", imgdata.Headers["ETag"])
|
2021-09-29 12:23:54 +02:00
|
|
|
rw.WriteHeader(200)
|
2021-09-30 18:00:28 +02:00
|
|
|
rw.Write(imgdata.Data)
|
2021-09-29 12:23:54 +02:00
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
header := make(http.Header)
|
2021-09-30 18:00:28 +02:00
|
|
|
header.Set("If-None-Match", expectedETag)
|
2021-09-29 12:23:54 +02:00
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
|
2021-09-29 12:23:54 +02:00
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Equal(actualETag, res.Header.Get("ETag"))
|
2021-09-29 12:23:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestETagDataNotMatch() {
|
|
|
|
config.ETagEnabled = true
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
poStr, imgdata, actualETag := s.sampleETagData("")
|
|
|
|
// Change the data hash
|
|
|
|
expectedETag := actualETag[:strings.IndexByte(actualETag, '/')] + "/Dasdbefj"
|
|
|
|
|
2021-09-29 12:23:54 +02:00
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Empty(r.Header.Get("If-None-Match"))
|
2021-09-29 12:23:54 +02:00
|
|
|
|
|
|
|
rw.WriteHeader(200)
|
2021-09-30 18:00:28 +02:00
|
|
|
rw.Write(imgdata.Data)
|
2021-09-29 12:23:54 +02:00
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
header := make(http.Header)
|
2021-09-30 18:00:28 +02:00
|
|
|
header.Set("If-None-Match", expectedETag)
|
2021-09-29 12:23:54 +02:00
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
|
2021-09-29 12:23:54 +02:00
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Equal(actualETag, res.Header.Get("ETag"))
|
2021-09-29 12:23:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestETagProcessingOptionsNotMatch() {
|
|
|
|
config.ETagEnabled = true
|
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
poStr, imgdata, actualETag := s.sampleETagData("")
|
|
|
|
// Change the processing options hash
|
|
|
|
expectedETag := "abcdefj" + actualETag[strings.IndexByte(actualETag, '/'):]
|
|
|
|
|
2021-09-29 12:23:54 +02:00
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Empty(r.Header.Get("If-None-Match"))
|
2021-09-29 12:23:54 +02:00
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
rw.Header().Set("ETag", imgdata.Headers["ETag"])
|
2021-09-29 12:23:54 +02:00
|
|
|
rw.WriteHeader(200)
|
2021-09-30 18:00:28 +02:00
|
|
|
rw.Write(imgdata.Data)
|
2021-09-29 12:23:54 +02:00
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
header := make(http.Header)
|
2021-09-30 18:00:28 +02:00
|
|
|
header.Set("If-None-Match", expectedETag)
|
2021-09-29 12:23:54 +02:00
|
|
|
|
2021-09-30 18:00:28 +02:00
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
|
2021-09-29 12:23:54 +02:00
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Equal(actualETag, res.Header.Get("ETag"))
|
2021-09-29 12:23:54 +02:00
|
|
|
}
|
|
|
|
|
2023-05-03 17:21:46 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestLastModifiedEnabled() {
|
|
|
|
config.LastModifiedEnabled = true
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
rw.Header().Set("Last-Modified", "Wed, 21 Oct 2015 07:28:00 GMT")
|
|
|
|
rw.WriteHeader(200)
|
|
|
|
rw.Write(s.readTestFile("test1.png"))
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal("Wed, 21 Oct 2015 07:28:00 GMT", res.Header.Get("Last-Modified"))
|
2023-05-03 17:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestLastModifiedDisabled() {
|
|
|
|
config.LastModifiedEnabled = false
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
rw.Header().Set("Last-Modified", "Wed, 21 Oct 2015 07:28:00 GMT")
|
|
|
|
rw.WriteHeader(200)
|
|
|
|
rw.Write(s.readTestFile("test1.png"))
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal("", res.Header.Get("Last-Modified"))
|
2023-05-03 17:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqExactMatchLastModifiedDisabled() {
|
|
|
|
config.LastModifiedEnabled = false
|
|
|
|
data := s.readTestFile("test1.png")
|
|
|
|
lastModified := "Wed, 21 Oct 2015 07:28:00 GMT"
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
modifiedSince := r.Header.Get("If-Modified-Since")
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Empty(modifiedSince)
|
2023-05-03 17:21:46 +02:00
|
|
|
rw.WriteHeader(200)
|
|
|
|
rw.Write(data)
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
header := make(http.Header)
|
|
|
|
header.Set("If-Modified-Since", lastModified)
|
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2023-05-03 17:21:46 +02:00
|
|
|
}
|
2024-03-25 16:53:43 +02:00
|
|
|
|
2023-05-03 17:21:46 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqExactMatchLastModifiedEnabled() {
|
|
|
|
config.LastModifiedEnabled = true
|
|
|
|
lastModified := "Wed, 21 Oct 2015 07:28:00 GMT"
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
modifiedSince := r.Header.Get("If-Modified-Since")
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(lastModified, modifiedSince)
|
2023-05-03 17:21:46 +02:00
|
|
|
rw.WriteHeader(304)
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
header := make(http.Header)
|
|
|
|
header.Set("If-Modified-Since", lastModified)
|
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(304, res.StatusCode)
|
2023-05-03 17:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareMoreRecentLastModifiedDisabled() {
|
|
|
|
data := s.readTestFile("test1.png")
|
|
|
|
config.LastModifiedEnabled = false
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
modifiedSince := r.Header.Get("If-Modified-Since")
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Empty(modifiedSince)
|
2023-05-03 17:21:46 +02:00
|
|
|
rw.WriteHeader(200)
|
|
|
|
rw.Write(data)
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
recentTimestamp := "Thu, 25 Feb 2021 01:45:00 GMT"
|
|
|
|
|
|
|
|
header := make(http.Header)
|
|
|
|
header.Set("If-Modified-Since", recentTimestamp)
|
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2023-05-03 17:21:46 +02:00
|
|
|
}
|
2024-03-25 16:53:43 +02:00
|
|
|
|
2023-05-03 17:21:46 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareMoreRecentLastModifiedEnabled() {
|
|
|
|
config.LastModifiedEnabled = true
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
fileLastModified, _ := time.Parse(http.TimeFormat, "Wed, 21 Oct 2015 07:28:00 GMT")
|
|
|
|
modifiedSince := r.Header.Get("If-Modified-Since")
|
|
|
|
parsedModifiedSince, err := time.Parse(http.TimeFormat, modifiedSince)
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(fileLastModified.Before(parsedModifiedSince))
|
2023-05-03 17:21:46 +02:00
|
|
|
rw.WriteHeader(304)
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
recentTimestamp := "Thu, 25 Feb 2021 01:45:00 GMT"
|
|
|
|
|
|
|
|
header := make(http.Header)
|
|
|
|
header.Set("If-Modified-Since", recentTimestamp)
|
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(304, res.StatusCode)
|
2023-05-03 17:21:46 +02:00
|
|
|
}
|
2024-03-25 16:53:43 +02:00
|
|
|
|
2023-05-03 17:21:46 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareTooOldLastModifiedDisabled() {
|
|
|
|
config.LastModifiedEnabled = false
|
|
|
|
data := s.readTestFile("test1.png")
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
modifiedSince := r.Header.Get("If-Modified-Since")
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Empty(modifiedSince)
|
2023-05-03 17:21:46 +02:00
|
|
|
rw.WriteHeader(200)
|
|
|
|
rw.Write(data)
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
oldTimestamp := "Tue, 01 Oct 2013 17:31:00 GMT"
|
|
|
|
|
|
|
|
header := make(http.Header)
|
|
|
|
header.Set("If-Modified-Since", oldTimestamp)
|
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2023-05-03 17:21:46 +02:00
|
|
|
}
|
2024-03-25 16:53:43 +02:00
|
|
|
|
2023-05-03 17:21:46 +02:00
|
|
|
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareTooOldLastModifiedEnabled() {
|
|
|
|
config.LastModifiedEnabled = true
|
|
|
|
data := s.readTestFile("test1.png")
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
fileLastModified, _ := time.Parse(http.TimeFormat, "Wed, 21 Oct 2015 07:28:00 GMT")
|
|
|
|
modifiedSince := r.Header.Get("If-Modified-Since")
|
|
|
|
parsedModifiedSince, err := time.Parse(http.TimeFormat, modifiedSince)
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(fileLastModified.After(parsedModifiedSince))
|
2023-05-03 17:21:46 +02:00
|
|
|
rw.WriteHeader(200)
|
|
|
|
rw.Write(data)
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
oldTimestamp := "Tue, 01 Oct 2013 17:31:00 GMT"
|
|
|
|
|
|
|
|
header := make(http.Header)
|
|
|
|
header.Set("If-Modified-Since", oldTimestamp)
|
|
|
|
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
2023-05-03 17:21:46 +02:00
|
|
|
}
|
2024-03-25 16:53:43 +02:00
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvg() {
|
|
|
|
config.AlwaysRasterizeSvg = true
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/rs:fill:40:40/plain/local:///test1.svg")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Equal("image/png", res.Header.Get("Content-Type"))
|
2024-03-25 16:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvgWithEnforceAvif() {
|
|
|
|
config.AlwaysRasterizeSvg = true
|
|
|
|
config.EnforceWebp = true
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/plain/local:///test1.svg", http.Header{"Accept": []string{"image/webp"}})
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Equal("image/webp", res.Header.Get("Content-Type"))
|
2024-03-25 16:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvgDisabled() {
|
|
|
|
config.AlwaysRasterizeSvg = false
|
|
|
|
config.EnforceWebp = true
|
|
|
|
|
|
|
|
rw := s.send("/unsafe/plain/local:///test1.svg")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Equal("image/svg+xml", res.Header.Get("Content-Type"))
|
2024-03-25 16:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvgWithFormat() {
|
|
|
|
config.AlwaysRasterizeSvg = true
|
|
|
|
config.SkipProcessingFormats = []imagetype.Type{imagetype.SVG}
|
|
|
|
rw := s.send("/unsafe/plain/local:///test1.svg@svg")
|
|
|
|
res := rw.Result()
|
|
|
|
|
2024-04-18 20:16:32 +02:00
|
|
|
s.Require().Equal(200, res.StatusCode)
|
|
|
|
s.Require().Equal("image/svg+xml", res.Header.Get("Content-Type"))
|
2024-03-25 16:53:43 +02:00
|
|
|
}
|
|
|
|
|
2021-04-26 13:52:50 +02:00
|
|
|
func TestProcessingHandler(t *testing.T) {
|
|
|
|
suite.Run(t, new(ProcessingHandlerTestSuite))
|
|
|
|
}
|