|
|
@@ -3,13 +3,13 @@ package optionsparser
|
|
|
import (
|
|
|
"encoding/base64"
|
|
|
"fmt"
|
|
|
- "net/http"
|
|
|
"net/url"
|
|
|
"regexp"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
"time"
|
|
|
|
|
|
+ "github.com/imgproxy/imgproxy/v3/clientfeatures"
|
|
|
"github.com/imgproxy/imgproxy/v3/imagetype"
|
|
|
"github.com/imgproxy/imgproxy/v3/options"
|
|
|
"github.com/imgproxy/imgproxy/v3/options/keys"
|
|
|
@@ -50,7 +50,7 @@ func (s *ProcessingOptionsTestSuite) SetupSubTest() {
|
|
|
func (s *ProcessingOptionsTestSuite) TestParseBase64URL() {
|
|
|
originURL := "http://images.dev/lorem/ipsum.jpg?param=value"
|
|
|
path := fmt.Sprintf("/size:100:100/%s.png", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal(originURL, imageURL)
|
|
|
@@ -62,7 +62,7 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithFilename() {
|
|
|
|
|
|
originURL := "http://images.dev/lorem/ipsum.jpg?param=value"
|
|
|
path := fmt.Sprintf("/size:100:100/%s.png/puppy.jpg", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal(originURL, imageURL)
|
|
|
@@ -72,7 +72,7 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithFilename() {
|
|
|
func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithoutExtension() {
|
|
|
originURL := "http://images.dev/lorem/ipsum.jpg?param=value"
|
|
|
path := fmt.Sprintf("/size:100:100/%s", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal(originURL, imageURL)
|
|
|
@@ -84,7 +84,7 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithBase() {
|
|
|
|
|
|
originURL := "lorem/ipsum.jpg?param=value"
|
|
|
path := fmt.Sprintf("/size:100:100/%s.png", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal(fmt.Sprintf("%s%s", s.config().BaseURL, originURL), imageURL)
|
|
|
@@ -99,7 +99,7 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithReplacement() {
|
|
|
|
|
|
originURL := "test://lorem/ipsum.jpg?param=value"
|
|
|
path := fmt.Sprintf("/size:100:100/%s.png", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal("http://images.dev/lorem/dolor/ipsum.jpg?param=value", imageURL)
|
|
|
@@ -109,7 +109,7 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithReplacement() {
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePlainURL() {
|
|
|
originURL := "http://images.dev/lorem/ipsum.jpg"
|
|
|
path := fmt.Sprintf("/size:100:100/plain/%s@png", originURL)
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal(originURL, imageURL)
|
|
|
@@ -120,7 +120,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithoutExtension() {
|
|
|
originURL := "http://images.dev/lorem/ipsum.jpg"
|
|
|
path := fmt.Sprintf("/size:100:100/plain/%s", originURL)
|
|
|
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal(originURL, imageURL)
|
|
|
@@ -129,7 +129,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithoutExtension() {
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscaped() {
|
|
|
originURL := "http://images.dev/lorem/ipsum.jpg?param=value"
|
|
|
path := fmt.Sprintf("/size:100:100/plain/%s@png", url.PathEscape(originURL))
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal(originURL, imageURL)
|
|
|
@@ -141,7 +141,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithBase() {
|
|
|
|
|
|
originURL := "lorem/ipsum.jpg"
|
|
|
path := fmt.Sprintf("/size:100:100/plain/%s@png", originURL)
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal(fmt.Sprintf("%s%s", s.config().BaseURL, originURL), imageURL)
|
|
|
@@ -156,7 +156,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithReplacement() {
|
|
|
|
|
|
originURL := "test://lorem/ipsum.jpg"
|
|
|
path := fmt.Sprintf("/size:100:100/plain/%s@png", originURL)
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal("http://images.dev/lorem/dolor/ipsum.jpg", imageURL)
|
|
|
@@ -168,7 +168,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
|
|
|
|
|
|
originURL := "lorem/ipsum.jpg?param=value"
|
|
|
path := fmt.Sprintf("/size:100:100/plain/%s@png", url.PathEscape(originURL))
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal(fmt.Sprintf("%s%s", s.config().BaseURL, originURL), imageURL)
|
|
|
@@ -179,7 +179,7 @@ func (s *ProcessingOptionsTestSuite) TestParseWithArgumentsSeparator() {
|
|
|
s.config().ArgumentsSeparator = ","
|
|
|
|
|
|
path := "/size,100,100,1/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -190,7 +190,7 @@ func (s *ProcessingOptionsTestSuite) TestParseWithArgumentsSeparator() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathFormat() {
|
|
|
path := "/format:webp/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -199,7 +199,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathFormat() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathResize() {
|
|
|
path := "/resize:fill:100:200:1/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -211,7 +211,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathResize() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathResizingType() {
|
|
|
path := "/resizing_type:fill/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -220,7 +220,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathResizingType() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathSize() {
|
|
|
path := "/size:100:200:1/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -231,7 +231,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathSize() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathWidth() {
|
|
|
path := "/width:100/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -240,7 +240,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWidth() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathHeight() {
|
|
|
path := "/height:100/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -249,7 +249,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathHeight() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathEnlarge() {
|
|
|
path := "/enlarge:1/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -258,7 +258,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathEnlarge() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathExtend() {
|
|
|
path := "/extend:1:so:10:20/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -273,21 +273,21 @@ func (s *ProcessingOptionsTestSuite) TestParsePathExtend() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathExtendSmartGravity() {
|
|
|
path := "/extend:1:sm/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- _, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ _, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().Error(err)
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathExtendReplicateGravity() {
|
|
|
path := "/extend:1:re/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- _, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ _, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().Error(err)
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathGravity() {
|
|
|
path := "/gravity:soea/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -299,7 +299,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathGravity() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathGravityFocusPoint() {
|
|
|
path := "/gravity:fp:0.5:0.75/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -310,14 +310,14 @@ func (s *ProcessingOptionsTestSuite) TestParsePathGravityFocusPoint() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathGravityReplicate() {
|
|
|
path := "/gravity:re/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- _, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ _, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().Error(err)
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathCrop() {
|
|
|
path := "/crop:100:200/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -333,7 +333,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathCrop() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathCropGravity() {
|
|
|
path := "/crop:100:200:nowe:10:20/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -349,14 +349,14 @@ func (s *ProcessingOptionsTestSuite) TestParsePathCropGravity() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathCropGravityReplicate() {
|
|
|
path := "/crop:100:200:re/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- _, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ _, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().Error(err)
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathQuality() {
|
|
|
path := "/quality:55/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -365,7 +365,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathQuality() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathBackground() {
|
|
|
path := "/background:128:129:130/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -377,7 +377,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathBackground() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathBackgroundHex() {
|
|
|
path := "/background:ffddee/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -389,7 +389,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathBackgroundHex() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathBackgroundDisable() {
|
|
|
path := "/background:fff/background:/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -398,7 +398,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathBackgroundDisable() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathBlur() {
|
|
|
path := "/blur:0.2/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -407,7 +407,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathBlur() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathSharpen() {
|
|
|
path := "/sharpen:0.2/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -416,7 +416,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathSharpen() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathDpr() {
|
|
|
path := "/dpr:2/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -425,7 +425,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathDpr() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathWatermark() {
|
|
|
path := "/watermark:0.5:soea:10:20:0.6/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -446,7 +446,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPreset() {
|
|
|
}
|
|
|
|
|
|
path := "/preset:test1:test2/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -462,7 +462,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPresetDefault() {
|
|
|
}
|
|
|
|
|
|
path := "/quality:70/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -479,7 +479,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPresetLoopDetection() {
|
|
|
}
|
|
|
|
|
|
path := "/preset:test1/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -488,7 +488,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPresetLoopDetection() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathCachebuster() {
|
|
|
path := "/cachebuster:123/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -497,7 +497,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathCachebuster() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathStripMetadata() {
|
|
|
path := "/strip_metadata:true/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -505,159 +505,159 @@ func (s *ProcessingOptionsTestSuite) TestParsePathStripMetadata() {
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathWebpDetection() {
|
|
|
- s.config().AutoWebp = true
|
|
|
-
|
|
|
path := "/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- headers := http.Header{"Accept": []string{"image/webp"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
+ features := clientfeatures.Features{PreferWebP: true}
|
|
|
+ o, _, err := s.parser().ParsePath(path, &features)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
s.Require().True(o.GetBool(keys.PreferWebP, false))
|
|
|
s.Require().False(o.GetBool(keys.EnforceWebP, false))
|
|
|
+ s.Require().False(o.GetBool(keys.PreferAvif, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceAvif, false))
|
|
|
+ s.Require().False(o.GetBool(keys.PreferJxl, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceJxl, false))
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathWebpEnforce() {
|
|
|
- s.config().EnforceWebp = true
|
|
|
-
|
|
|
path := "/plain/http://images.dev/lorem/ipsum.jpg@png"
|
|
|
- headers := http.Header{"Accept": []string{"image/webp"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
+ features := clientfeatures.Features{EnforceWebP: true}
|
|
|
+ o, _, err := s.parser().ParsePath(path, &features)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
s.Require().True(o.GetBool(keys.PreferWebP, false))
|
|
|
s.Require().True(o.GetBool(keys.EnforceWebP, false))
|
|
|
+ s.Require().False(o.GetBool(keys.PreferAvif, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceAvif, false))
|
|
|
+ s.Require().False(o.GetBool(keys.PreferJxl, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceJxl, false))
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathAvifDetection() {
|
|
|
- s.config().AutoAvif = true
|
|
|
-
|
|
|
path := "/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- headers := http.Header{"Accept": []string{"image/avif"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
+ features := clientfeatures.Features{PreferAvif: true}
|
|
|
+ o, _, err := s.parser().ParsePath(path, &features)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
+ s.Require().False(o.GetBool(keys.PreferWebP, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceWebP, false))
|
|
|
s.Require().True(o.GetBool(keys.PreferAvif, false))
|
|
|
s.Require().False(o.GetBool(keys.EnforceAvif, false))
|
|
|
+ s.Require().False(o.GetBool(keys.PreferJxl, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceJxl, false))
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathAvifEnforce() {
|
|
|
- s.config().EnforceAvif = true
|
|
|
-
|
|
|
path := "/plain/http://images.dev/lorem/ipsum.jpg@png"
|
|
|
- headers := http.Header{"Accept": []string{"image/avif"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
+ features := clientfeatures.Features{EnforceAvif: true}
|
|
|
+ o, _, err := s.parser().ParsePath(path, &features)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
+ s.Require().False(o.GetBool(keys.PreferWebP, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceWebP, false))
|
|
|
s.Require().True(o.GetBool(keys.PreferAvif, false))
|
|
|
s.Require().True(o.GetBool(keys.EnforceAvif, false))
|
|
|
+ s.Require().False(o.GetBool(keys.PreferJxl, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceJxl, false))
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathJxlDetection() {
|
|
|
- s.config().AutoJxl = true
|
|
|
-
|
|
|
path := "/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- headers := http.Header{"Accept": []string{"image/jxl"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
+ features := clientfeatures.Features{PreferJxl: true}
|
|
|
+ o, _, err := s.parser().ParsePath(path, &features)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
+ s.Require().False(o.GetBool(keys.PreferWebP, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceWebP, false))
|
|
|
+ s.Require().False(o.GetBool(keys.PreferAvif, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceAvif, false))
|
|
|
s.Require().True(o.GetBool(keys.PreferJxl, false))
|
|
|
s.Require().False(o.GetBool(keys.EnforceJxl, false))
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParsePathJxlEnforce() {
|
|
|
- s.config().EnforceJxl = true
|
|
|
-
|
|
|
path := "/plain/http://images.dev/lorem/ipsum.jpg@png"
|
|
|
- headers := http.Header{"Accept": []string{"image/jxl"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
+ features := clientfeatures.Features{EnforceJxl: true}
|
|
|
+ o, _, err := s.parser().ParsePath(path, &features)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
+ s.Require().False(o.GetBool(keys.PreferWebP, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceWebP, false))
|
|
|
+ s.Require().False(o.GetBool(keys.PreferAvif, false))
|
|
|
+ s.Require().False(o.GetBool(keys.EnforceAvif, false))
|
|
|
s.Require().True(o.GetBool(keys.PreferJxl, false))
|
|
|
s.Require().True(o.GetBool(keys.EnforceJxl, false))
|
|
|
}
|
|
|
|
|
|
-func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeader() {
|
|
|
- s.config().EnableClientHints = true
|
|
|
-
|
|
|
+func (s *ProcessingOptionsTestSuite) TestParsePathClientHints() {
|
|
|
path := "/plain/http://images.dev/lorem/ipsum.jpg@png"
|
|
|
- headers := http.Header{"Width": []string{"100"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
-
|
|
|
- s.Require().NoError(err)
|
|
|
-
|
|
|
- s.Require().Equal(100, o.GetInt(keys.Width, 0))
|
|
|
-}
|
|
|
-
|
|
|
-func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderDisabled() {
|
|
|
- path := "/plain/http://images.dev/lorem/ipsum.jpg@png"
|
|
|
- headers := http.Header{"Width": []string{"100"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
-
|
|
|
- s.Require().NoError(err)
|
|
|
-
|
|
|
- s.Require().Equal(0, o.GetInt(keys.Width, 0))
|
|
|
-}
|
|
|
-
|
|
|
-func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderRedefine() {
|
|
|
- s.config().EnableClientHints = true
|
|
|
|
|
|
- path := "/width:150/plain/http://images.dev/lorem/ipsum.jpg@png"
|
|
|
- headers := http.Header{"Width": []string{"100"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
-
|
|
|
- s.Require().NoError(err)
|
|
|
-
|
|
|
- s.Require().Equal(150, o.GetInt(keys.Width, 0))
|
|
|
-}
|
|
|
-
|
|
|
-func (s *ProcessingOptionsTestSuite) TestParsePathDprHeader() {
|
|
|
- s.config().EnableClientHints = true
|
|
|
-
|
|
|
- path := "/plain/http://images.dev/lorem/ipsum.jpg@png"
|
|
|
- headers := http.Header{"Dpr": []string{"2"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
-
|
|
|
- s.Require().NoError(err)
|
|
|
-
|
|
|
- s.Require().InDelta(2.0, o.GetFloat(keys.Dpr, 1.0), 0.0001)
|
|
|
-}
|
|
|
-
|
|
|
-func (s *ProcessingOptionsTestSuite) TestParsePathDprHeaderDisabled() {
|
|
|
- path := "/plain/http://images.dev/lorem/ipsum.jpg@png"
|
|
|
- headers := http.Header{"Dpr": []string{"2"}}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
+ testCases := []struct {
|
|
|
+ name string
|
|
|
+ features clientfeatures.Features
|
|
|
+ width int
|
|
|
+ dpr float64
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ name: "NoClientHints",
|
|
|
+ features: clientfeatures.Features{},
|
|
|
+ width: 0,
|
|
|
+ dpr: 1.0,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "WidthOnly",
|
|
|
+ features: clientfeatures.Features{ClientHintsWidth: 100},
|
|
|
+ width: 100,
|
|
|
+ dpr: 1.0,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "DprOnly",
|
|
|
+ features: clientfeatures.Features{ClientHintsDPR: 2.0},
|
|
|
+ width: 0,
|
|
|
+ dpr: 2.0,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "WidthAndDpr",
|
|
|
+ features: clientfeatures.Features{ClientHintsWidth: 100, ClientHintsDPR: 2.0},
|
|
|
+ width: 50,
|
|
|
+ dpr: 2.0,
|
|
|
+ },
|
|
|
+ }
|
|
|
|
|
|
- s.Require().NoError(err)
|
|
|
+ for _, tc := range testCases {
|
|
|
+ s.Run(tc.name, func() {
|
|
|
+ o, _, err := s.parser().ParsePath(path, &tc.features)
|
|
|
|
|
|
- s.Require().InDelta(1.0, o.GetFloat(keys.Dpr, 1.0), 0.0001)
|
|
|
+ s.Require().NoError(err)
|
|
|
+ s.Require().Equal(tc.width, o.GetInt(keys.Width, 0))
|
|
|
+ s.Require().InDelta(tc.dpr, o.GetFloat(keys.Dpr, 1.0), 0.0001)
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-func (s *ProcessingOptionsTestSuite) TestParsePathWidthAndDprHeaderCombined() {
|
|
|
- s.config().EnableClientHints = true
|
|
|
-
|
|
|
- path := "/plain/http://images.dev/lorem/ipsum.jpg@png"
|
|
|
- headers := http.Header{
|
|
|
- "Width": []string{"100"},
|
|
|
- "Dpr": []string{"2"},
|
|
|
+func (s *ProcessingOptionsTestSuite) TestParsePathClientHintsRedefine() {
|
|
|
+ path := "/width:150/dpr:3.0/plain/http://images.dev/lorem/ipsum.jpg@png"
|
|
|
+ features := clientfeatures.Features{
|
|
|
+ ClientHintsWidth: 100,
|
|
|
+ ClientHintsDPR: 2.0,
|
|
|
}
|
|
|
- o, _, err := s.parser().ParsePath(path, headers)
|
|
|
+ o, _, err := s.parser().ParsePath(path, &features)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
- s.Require().Equal(50, o.GetInt(keys.Width, 0))
|
|
|
- s.Require().InDelta(2.0, o.GetFloat(keys.Dpr, 1.0), 0.0001)
|
|
|
+ s.Require().Equal(150, o.GetInt(keys.Width, 0))
|
|
|
+ s.Require().InDelta(3.0, o.GetFloat(keys.Dpr, 1.0), 0.0001)
|
|
|
}
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParseSkipProcessing() {
|
|
|
path := "/skp:jpg:png/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -670,7 +670,7 @@ func (s *ProcessingOptionsTestSuite) TestParseSkipProcessing() {
|
|
|
func (s *ProcessingOptionsTestSuite) TestParseSkipProcessingInvalid() {
|
|
|
path := "/skp:jpg:png:bad_format/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
|
|
|
- _, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ _, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().Error(err)
|
|
|
s.Require().Equal("Invalid image format in skip_processing: bad_format", err.Error())
|
|
|
@@ -678,7 +678,7 @@ func (s *ProcessingOptionsTestSuite) TestParseSkipProcessingInvalid() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParseExpires() {
|
|
|
path := "/exp:32503669200/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- o, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
s.Require().Equal(time.Unix(32503669200, 0), o.GetTime(keys.Expires))
|
|
|
@@ -686,7 +686,7 @@ func (s *ProcessingOptionsTestSuite) TestParseExpires() {
|
|
|
|
|
|
func (s *ProcessingOptionsTestSuite) TestParseExpiresExpired() {
|
|
|
path := "/exp:1609448400/plain/http://images.dev/lorem/ipsum.jpg"
|
|
|
- _, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ _, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().Error(err, "Expired URL")
|
|
|
}
|
|
|
@@ -701,7 +701,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
|
|
|
originURL := "http://images.dev/lorem/ipsum.jpg"
|
|
|
path := "/test1:test2/plain/" + originURL + "@png"
|
|
|
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -721,7 +721,7 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLOnlyPresets() {
|
|
|
originURL := "http://images.dev/lorem/ipsum.jpg?param=value"
|
|
|
path := fmt.Sprintf("/test1:test2/%s.png", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
|
|
|
|
|
- o, imageURL, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ o, imageURL, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
@@ -752,7 +752,7 @@ func (s *ProcessingOptionsTestSuite) TestParseAllowedOptions() {
|
|
|
}
|
|
|
|
|
|
path := fmt.Sprintf("/%s/%s.png", tc.options, base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
|
|
- _, _, err := s.parser().ParsePath(path, make(http.Header))
|
|
|
+ _, _, err := s.parser().ParsePath(path, nil)
|
|
|
|
|
|
if len(tc.expectedError) > 0 {
|
|
|
s.Require().Error(err)
|