mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-18 16:31:44 +02:00
Update linter and fix linting errors
This commit is contained in:
parent
09e542517a
commit
e31b24931d
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
@ -27,7 +27,7 @@ jobs:
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
version: v1.55.0
|
||||
version: v1.57.2
|
||||
args: --timeout 5m0s
|
||||
skip-cache: true
|
||||
env:
|
||||
|
@ -1,8 +1,3 @@
|
||||
run:
|
||||
skip-dirs:
|
||||
- .tmp
|
||||
- vendor
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
@ -17,27 +12,36 @@ linters:
|
||||
- stylecheck
|
||||
- typecheck
|
||||
- unused
|
||||
- bodyclose
|
||||
- testifylint
|
||||
|
||||
linters-settings:
|
||||
govet:
|
||||
# report about shadowed variables
|
||||
check-shadowing: true
|
||||
enable-all: true
|
||||
disable:
|
||||
- fieldalignment
|
||||
|
||||
issues:
|
||||
exclude-dirs:
|
||||
- .tmp
|
||||
- vendor
|
||||
exclude-rules:
|
||||
# - path: _test\.go
|
||||
# linters:
|
||||
# - goconst
|
||||
|
||||
- linters: [bodyclose]
|
||||
path: ".*_test.go"
|
||||
|
||||
# False positives on CGO generated code
|
||||
- linters: [staticcheck]
|
||||
text: "SA4000:"
|
||||
path: vips/*
|
||||
path: vips/.*
|
||||
|
||||
# False positives on CGO generated code
|
||||
- linters: [gocritic]
|
||||
text: "dupSubExpr"
|
||||
path: vips/*
|
||||
path: vips/.*
|
||||
|
||||
- linters: [stylecheck]
|
||||
text: "ST1005:"
|
||||
|
@ -6,12 +6,12 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
"github.com/imgproxy/imgproxy/v3/imagedata"
|
||||
"github.com/imgproxy/imgproxy/v3/options"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -52,31 +52,31 @@ func (s *EtagTestSuite) TestGenerateActualReq() {
|
||||
s.h.SetActualProcessingOptions(po)
|
||||
s.h.SetActualImageData(&imgWithETag)
|
||||
|
||||
require.Equal(s.T(), etagReq, s.h.GenerateActualETag())
|
||||
s.Require().Equal(etagReq, s.h.GenerateActualETag())
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestGenerateActualData() {
|
||||
s.h.SetActualProcessingOptions(po)
|
||||
s.h.SetActualImageData(&imgWithoutETag)
|
||||
|
||||
require.Equal(s.T(), etagData, s.h.GenerateActualETag())
|
||||
s.Require().Equal(etagData, s.h.GenerateActualETag())
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestGenerateExpectedReq() {
|
||||
s.h.ParseExpectedETag(etagReq)
|
||||
require.Equal(s.T(), etagReq, s.h.GenerateExpectedETag())
|
||||
s.Require().Equal(etagReq, s.h.GenerateExpectedETag())
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestGenerateExpectedData() {
|
||||
s.h.ParseExpectedETag(etagData)
|
||||
require.Equal(s.T(), etagData, s.h.GenerateExpectedETag())
|
||||
s.Require().Equal(etagData, s.h.GenerateExpectedETag())
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestProcessingOptionsCheckSuccess() {
|
||||
s.h.ParseExpectedETag(etagReq)
|
||||
|
||||
require.True(s.T(), s.h.SetActualProcessingOptions(po))
|
||||
require.True(s.T(), s.h.ProcessingOptionsMatch())
|
||||
s.Require().True(s.h.SetActualProcessingOptions(po))
|
||||
s.Require().True(s.h.ProcessingOptionsMatch())
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestProcessingOptionsCheckFailure() {
|
||||
@ -85,25 +85,26 @@ func (s *EtagTestSuite) TestProcessingOptionsCheckFailure() {
|
||||
|
||||
s.h.ParseExpectedETag(wrongEtag)
|
||||
|
||||
require.False(s.T(), s.h.SetActualProcessingOptions(po))
|
||||
require.False(s.T(), s.h.ProcessingOptionsMatch())
|
||||
s.Require().False(s.h.SetActualProcessingOptions(po))
|
||||
s.Require().False(s.h.ProcessingOptionsMatch())
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestImageETagExpectedPresent() {
|
||||
s.h.ParseExpectedETag(etagReq)
|
||||
|
||||
require.Equal(s.T(), imgWithETag.Headers["ETag"], s.h.ImageEtagExpected())
|
||||
//nolint:testifylint // False-positive expected-actual
|
||||
s.Require().Equal(imgWithETag.Headers["ETag"], s.h.ImageEtagExpected())
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestImageETagExpectedBlank() {
|
||||
s.h.ParseExpectedETag(etagData)
|
||||
|
||||
require.Empty(s.T(), s.h.ImageEtagExpected())
|
||||
s.Require().Empty(s.h.ImageEtagExpected())
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestImageDataCheckDataToDataSuccess() {
|
||||
s.h.ParseExpectedETag(etagData)
|
||||
require.True(s.T(), s.h.SetActualImageData(&imgWithoutETag))
|
||||
s.Require().True(s.h.SetActualImageData(&imgWithoutETag))
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestImageDataCheckDataToDataFailure() {
|
||||
@ -111,12 +112,12 @@ func (s *EtagTestSuite) TestImageDataCheckDataToDataFailure() {
|
||||
wrongEtag := etagData[:i] + `/Dwrongimghash"`
|
||||
|
||||
s.h.ParseExpectedETag(wrongEtag)
|
||||
require.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
|
||||
s.Require().False(s.h.SetActualImageData(&imgWithoutETag))
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestImageDataCheckDataToReqSuccess() {
|
||||
s.h.ParseExpectedETag(etagData)
|
||||
require.True(s.T(), s.h.SetActualImageData(&imgWithETag))
|
||||
s.Require().True(s.h.SetActualImageData(&imgWithETag))
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestImageDataCheckDataToReqFailure() {
|
||||
@ -124,19 +125,19 @@ func (s *EtagTestSuite) TestImageDataCheckDataToReqFailure() {
|
||||
wrongEtag := etagData[:i] + `/Dwrongimghash"`
|
||||
|
||||
s.h.ParseExpectedETag(wrongEtag)
|
||||
require.False(s.T(), s.h.SetActualImageData(&imgWithETag))
|
||||
s.Require().False(s.h.SetActualImageData(&imgWithETag))
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestImageDataCheckReqToDataFailure() {
|
||||
s.h.ParseExpectedETag(etagReq)
|
||||
require.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
|
||||
s.Require().False(s.h.SetActualImageData(&imgWithoutETag))
|
||||
}
|
||||
|
||||
func (s *EtagTestSuite) TestETagBusterFailure() {
|
||||
config.ETagBuster = "busted"
|
||||
|
||||
s.h.ParseExpectedETag(etagReq)
|
||||
require.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
|
||||
s.Require().False(s.h.SetActualImageData(&imgWithoutETag))
|
||||
}
|
||||
|
||||
func TestEtag(t *testing.T) {
|
||||
|
@ -5,9 +5,9 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/imagetype"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/imagetype"
|
||||
)
|
||||
|
||||
type JpegTestSuite struct {
|
||||
@ -16,10 +16,10 @@ type JpegTestSuite struct {
|
||||
|
||||
func (s *JpegTestSuite) openFile(name string) *os.File {
|
||||
wd, err := os.Getwd()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
path := filepath.Join(wd, "..", "testdata", name)
|
||||
f, err := os.Open(path)
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
return f
|
||||
}
|
||||
|
||||
@ -41,8 +41,8 @@ func (s *JpegTestSuite) TestDecodeJpegMeta() {
|
||||
defer f.Close()
|
||||
|
||||
metadata, err := DecodeJpegMeta(f)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), expectedMeta, metadata)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(expectedMeta, metadata)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
@ -35,9 +34,9 @@ func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointNoProtocol() {
|
||||
|
||||
mapDeprecatedConfig()
|
||||
|
||||
require.True(s.T(), config.OpenTelemetryEnable)
|
||||
require.Equal(s.T(), "https://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"))
|
||||
require.Equal(s.T(), "", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))
|
||||
s.Require().True(config.OpenTelemetryEnable)
|
||||
s.Require().Equal("https://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"))
|
||||
s.Require().Equal("", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))
|
||||
}
|
||||
|
||||
func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointGrpcProtocol() {
|
||||
@ -46,9 +45,9 @@ func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointGrpcProtocol() {
|
||||
|
||||
mapDeprecatedConfig()
|
||||
|
||||
require.True(s.T(), config.OpenTelemetryEnable)
|
||||
require.Equal(s.T(), "https://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"))
|
||||
require.Equal(s.T(), "grpc", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))
|
||||
s.Require().True(config.OpenTelemetryEnable)
|
||||
s.Require().Equal("https://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"))
|
||||
s.Require().Equal("grpc", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))
|
||||
}
|
||||
|
||||
func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointGrpcProtocolInsecure() {
|
||||
@ -58,9 +57,9 @@ func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointGrpcProtocolInsecure() {
|
||||
|
||||
mapDeprecatedConfig()
|
||||
|
||||
require.True(s.T(), config.OpenTelemetryEnable)
|
||||
require.Equal(s.T(), "http://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"))
|
||||
require.Equal(s.T(), "grpc", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))
|
||||
s.Require().True(config.OpenTelemetryEnable)
|
||||
s.Require().Equal("http://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"))
|
||||
s.Require().Equal("grpc", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))
|
||||
}
|
||||
|
||||
func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointHttpsProtocol() {
|
||||
@ -69,9 +68,9 @@ func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointHttpsProtocol() {
|
||||
|
||||
mapDeprecatedConfig()
|
||||
|
||||
require.True(s.T(), config.OpenTelemetryEnable)
|
||||
require.Equal(s.T(), "https://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"))
|
||||
require.Equal(s.T(), "https", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))
|
||||
s.Require().True(config.OpenTelemetryEnable)
|
||||
s.Require().Equal("https://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"))
|
||||
s.Require().Equal("https", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))
|
||||
}
|
||||
|
||||
func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointHttpProtocol() {
|
||||
@ -80,9 +79,9 @@ func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointHttpProtocol() {
|
||||
|
||||
mapDeprecatedConfig()
|
||||
|
||||
require.True(s.T(), config.OpenTelemetryEnable)
|
||||
require.Equal(s.T(), "http://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"))
|
||||
require.Equal(s.T(), "http", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))
|
||||
s.Require().True(config.OpenTelemetryEnable)
|
||||
s.Require().Equal("http://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"))
|
||||
s.Require().Equal("http", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))
|
||||
}
|
||||
|
||||
func (s *OtelTestSuite) TestMapDeprecatedConfigServiceName() {
|
||||
@ -91,7 +90,7 @@ func (s *OtelTestSuite) TestMapDeprecatedConfigServiceName() {
|
||||
config.OpenTelemetryEnable = true
|
||||
mapDeprecatedConfig()
|
||||
|
||||
require.Equal(s.T(), "testtest", os.Getenv("OTEL_SERVICE_NAME"))
|
||||
s.Require().Equal("testtest", os.Getenv("OTEL_SERVICE_NAME"))
|
||||
}
|
||||
|
||||
func (s *OtelTestSuite) TestMapDeprecatedConfigPropagators() {
|
||||
@ -100,7 +99,7 @@ func (s *OtelTestSuite) TestMapDeprecatedConfigPropagators() {
|
||||
config.OpenTelemetryEnable = true
|
||||
mapDeprecatedConfig()
|
||||
|
||||
require.Equal(s.T(), "testtest", os.Getenv("OTEL_PROPAGATORS"))
|
||||
s.Require().Equal("testtest", os.Getenv("OTEL_PROPAGATORS"))
|
||||
}
|
||||
|
||||
func (s *OtelTestSuite) TestMapDeprecatedConfigConnectionTimeout() {
|
||||
@ -109,7 +108,7 @@ func (s *OtelTestSuite) TestMapDeprecatedConfigConnectionTimeout() {
|
||||
config.OpenTelemetryEnable = true
|
||||
mapDeprecatedConfig()
|
||||
|
||||
require.Equal(s.T(), "15000", os.Getenv("OTEL_EXPORTER_OTLP_TIMEOUT"))
|
||||
s.Require().Equal("15000", os.Getenv("OTEL_EXPORTER_OTLP_TIMEOUT"))
|
||||
}
|
||||
|
||||
func TestPresets(t *testing.T) {
|
||||
|
@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
)
|
||||
|
||||
type PresetsTestSuite struct{ suite.Suite }
|
||||
@ -20,9 +20,9 @@ func (s *PresetsTestSuite) SetupTest() {
|
||||
func (s *PresetsTestSuite) TestParsePreset() {
|
||||
err := parsePreset("test=resize:fit:100:200/sharpen:2")
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), urlOptions{
|
||||
s.Require().Equal(urlOptions{
|
||||
urlOption{Name: "resize", Args: []string{"fit", "100", "200"}},
|
||||
urlOption{Name: "sharpen", Args: []string{"2"}},
|
||||
}, presets["test"])
|
||||
@ -32,46 +32,46 @@ func (s *PresetsTestSuite) TestParsePresetInvalidString() {
|
||||
presetStr := "resize:fit:100:200/sharpen:2"
|
||||
err := parsePreset(presetStr)
|
||||
|
||||
require.Equal(s.T(), fmt.Errorf("Invalid preset string: %s", presetStr), err)
|
||||
require.Empty(s.T(), presets)
|
||||
s.Require().Equal(fmt.Errorf("Invalid preset string: %s", presetStr), err)
|
||||
s.Require().Empty(presets)
|
||||
}
|
||||
|
||||
func (s *PresetsTestSuite) TestParsePresetEmptyName() {
|
||||
presetStr := "=resize:fit:100:200/sharpen:2"
|
||||
err := parsePreset(presetStr)
|
||||
|
||||
require.Equal(s.T(), fmt.Errorf("Empty preset name: %s", presetStr), err)
|
||||
require.Empty(s.T(), presets)
|
||||
s.Require().Equal(fmt.Errorf("Empty preset name: %s", presetStr), err)
|
||||
s.Require().Empty(presets)
|
||||
}
|
||||
|
||||
func (s *PresetsTestSuite) TestParsePresetEmptyValue() {
|
||||
presetStr := "test="
|
||||
err := parsePreset(presetStr)
|
||||
|
||||
require.Equal(s.T(), fmt.Errorf("Empty preset value: %s", presetStr), err)
|
||||
require.Empty(s.T(), presets)
|
||||
s.Require().Equal(fmt.Errorf("Empty preset value: %s", presetStr), err)
|
||||
s.Require().Empty(presets)
|
||||
}
|
||||
|
||||
func (s *PresetsTestSuite) TestParsePresetInvalidValue() {
|
||||
presetStr := "test=resize:fit:100:200/sharpen:2/blur"
|
||||
err := parsePreset(presetStr)
|
||||
|
||||
require.Equal(s.T(), fmt.Errorf("Invalid preset value: %s", presetStr), err)
|
||||
require.Empty(s.T(), presets)
|
||||
s.Require().Equal(fmt.Errorf("Invalid preset value: %s", presetStr), err)
|
||||
s.Require().Empty(presets)
|
||||
}
|
||||
|
||||
func (s *PresetsTestSuite) TestParsePresetEmptyString() {
|
||||
err := parsePreset(" ")
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Empty(s.T(), presets)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Empty(presets)
|
||||
}
|
||||
|
||||
func (s *PresetsTestSuite) TestParsePresetComment() {
|
||||
err := parsePreset("# test=resize:fit:100:200/sharpen:2")
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Empty(s.T(), presets)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Empty(presets)
|
||||
}
|
||||
|
||||
func (s *PresetsTestSuite) TestValidatePresets() {
|
||||
@ -84,7 +84,7 @@ func (s *PresetsTestSuite) TestValidatePresets() {
|
||||
|
||||
err := ValidatePresets()
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *PresetsTestSuite) TestValidatePresetsInvalid() {
|
||||
@ -97,7 +97,7 @@ func (s *PresetsTestSuite) TestValidatePresetsInvalid() {
|
||||
|
||||
err := ValidatePresets()
|
||||
|
||||
require.Error(s.T(), err)
|
||||
s.Require().Error(err)
|
||||
}
|
||||
|
||||
func TestPresets(t *testing.T) {
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
@ -28,9 +27,9 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URL() {
|
||||
path := fmt.Sprintf("/size:100:100/%s.png", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), originURL, imageURL)
|
||||
require.Equal(s.T(), imagetype.PNG, po.Format)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(originURL, imageURL)
|
||||
s.Require().Equal(imagetype.PNG, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithoutExtension() {
|
||||
@ -38,9 +37,9 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithoutExtension() {
|
||||
path := fmt.Sprintf("/size:100:100/%s", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), originURL, imageURL)
|
||||
require.Equal(s.T(), imagetype.Unknown, po.Format)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(originURL, imageURL)
|
||||
s.Require().Equal(imagetype.Unknown, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithBase() {
|
||||
@ -50,9 +49,9 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithBase() {
|
||||
path := fmt.Sprintf("/size:100:100/%s.png", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
|
||||
require.Equal(s.T(), imagetype.PNG, po.Format)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
|
||||
s.Require().Equal(imagetype.PNG, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithReplacement() {
|
||||
@ -65,9 +64,9 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithReplacement() {
|
||||
path := fmt.Sprintf("/size:100:100/%s.png", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), "http://images.dev/lorem/dolor/ipsum.jpg?param=value", imageURL)
|
||||
require.Equal(s.T(), imagetype.PNG, po.Format)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal("http://images.dev/lorem/dolor/ipsum.jpg?param=value", imageURL)
|
||||
s.Require().Equal(imagetype.PNG, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePlainURL() {
|
||||
@ -75,9 +74,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURL() {
|
||||
path := fmt.Sprintf("/size:100:100/plain/%s@png", originURL)
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), originURL, imageURL)
|
||||
require.Equal(s.T(), imagetype.PNG, po.Format)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(originURL, imageURL)
|
||||
s.Require().Equal(imagetype.PNG, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithoutExtension() {
|
||||
@ -86,18 +85,18 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithoutExtension() {
|
||||
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), originURL, imageURL)
|
||||
require.Equal(s.T(), imagetype.Unknown, po.Format)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(originURL, imageURL)
|
||||
s.Require().Equal(imagetype.Unknown, po.Format)
|
||||
}
|
||||
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))
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), originURL, imageURL)
|
||||
require.Equal(s.T(), imagetype.PNG, po.Format)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(originURL, imageURL)
|
||||
s.Require().Equal(imagetype.PNG, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithBase() {
|
||||
@ -107,9 +106,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithBase() {
|
||||
path := fmt.Sprintf("/size:100:100/plain/%s@png", originURL)
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
|
||||
require.Equal(s.T(), imagetype.PNG, po.Format)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
|
||||
s.Require().Equal(imagetype.PNG, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithReplacement() {
|
||||
@ -122,9 +121,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithReplacement() {
|
||||
path := fmt.Sprintf("/size:100:100/plain/%s@png", originURL)
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), "http://images.dev/lorem/dolor/ipsum.jpg", imageURL)
|
||||
require.Equal(s.T(), imagetype.PNG, po.Format)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal("http://images.dev/lorem/dolor/ipsum.jpg", imageURL)
|
||||
s.Require().Equal(imagetype.PNG, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
|
||||
@ -134,9 +133,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
|
||||
path := fmt.Sprintf("/size:100:100/plain/%s@png", url.PathEscape(originURL))
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
|
||||
require.Equal(s.T(), imagetype.PNG, po.Format)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
|
||||
s.Require().Equal(imagetype.PNG, po.Format)
|
||||
}
|
||||
|
||||
// func (s *ProcessingOptionsTestSuite) TestParseURLAllowedSource() {
|
||||
@ -145,7 +144,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
|
||||
// path := "/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
// _, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
// require.Nil(s.T(), err)
|
||||
// s.Require().NoError(err)
|
||||
// }
|
||||
|
||||
// func (s *ProcessingOptionsTestSuite) TestParseURLNotAllowedSource() {
|
||||
@ -154,187 +153,187 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
|
||||
// path := "/plain/s3://images/lorem/ipsum.jpg"
|
||||
// _, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
// require.Error(s.T(), err)
|
||||
// s.Require().Error(err)
|
||||
// }
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathFormat() {
|
||||
path := "/format:webp/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), imagetype.WEBP, po.Format)
|
||||
s.Require().Equal(imagetype.WEBP, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathResize() {
|
||||
path := "/resize:fill:100:200:1/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), ResizeFill, po.ResizingType)
|
||||
require.Equal(s.T(), 100, po.Width)
|
||||
require.Equal(s.T(), 200, po.Height)
|
||||
require.True(s.T(), po.Enlarge)
|
||||
s.Require().Equal(ResizeFill, po.ResizingType)
|
||||
s.Require().Equal(100, po.Width)
|
||||
s.Require().Equal(200, po.Height)
|
||||
s.Require().True(po.Enlarge)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathResizingType() {
|
||||
path := "/resizing_type:fill/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), ResizeFill, po.ResizingType)
|
||||
s.Require().Equal(ResizeFill, po.ResizingType)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathSize() {
|
||||
path := "/size:100:200:1/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), 100, po.Width)
|
||||
require.Equal(s.T(), 200, po.Height)
|
||||
require.True(s.T(), po.Enlarge)
|
||||
s.Require().Equal(100, po.Width)
|
||||
s.Require().Equal(200, po.Height)
|
||||
s.Require().True(po.Enlarge)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathWidth() {
|
||||
path := "/width:100/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), 100, po.Width)
|
||||
s.Require().Equal(100, po.Width)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathHeight() {
|
||||
path := "/height:100/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), 100, po.Height)
|
||||
s.Require().Equal(100, po.Height)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathEnlarge() {
|
||||
path := "/enlarge:1/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.True(s.T(), po.Enlarge)
|
||||
s.Require().True(po.Enlarge)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathExtend() {
|
||||
path := "/extend:1:so:10:20/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), true, po.Extend.Enabled)
|
||||
require.Equal(s.T(), GravitySouth, po.Extend.Gravity.Type)
|
||||
require.Equal(s.T(), 10.0, po.Extend.Gravity.X)
|
||||
require.Equal(s.T(), 20.0, po.Extend.Gravity.Y)
|
||||
s.Require().True(po.Extend.Enabled)
|
||||
s.Require().Equal(GravitySouth, po.Extend.Gravity.Type)
|
||||
s.Require().InDelta(10.0, po.Extend.Gravity.X, 0.0001)
|
||||
s.Require().InDelta(20.0, po.Extend.Gravity.Y, 0.0001)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathGravity() {
|
||||
path := "/gravity:soea/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), GravitySouthEast, po.Gravity.Type)
|
||||
s.Require().Equal(GravitySouthEast, po.Gravity.Type)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathGravityFocuspoint() {
|
||||
path := "/gravity:fp:0.5:0.75/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), GravityFocusPoint, po.Gravity.Type)
|
||||
require.Equal(s.T(), 0.5, po.Gravity.X)
|
||||
require.Equal(s.T(), 0.75, po.Gravity.Y)
|
||||
s.Require().Equal(GravityFocusPoint, po.Gravity.Type)
|
||||
s.Require().InDelta(0.5, po.Gravity.X, 0.0001)
|
||||
s.Require().InDelta(0.75, po.Gravity.Y, 0.0001)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathQuality() {
|
||||
path := "/quality:55/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), 55, po.Quality)
|
||||
s.Require().Equal(55, po.Quality)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathBackground() {
|
||||
path := "/background:128:129:130/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.True(s.T(), po.Flatten)
|
||||
require.Equal(s.T(), uint8(128), po.Background.R)
|
||||
require.Equal(s.T(), uint8(129), po.Background.G)
|
||||
require.Equal(s.T(), uint8(130), po.Background.B)
|
||||
s.Require().True(po.Flatten)
|
||||
s.Require().Equal(uint8(128), po.Background.R)
|
||||
s.Require().Equal(uint8(129), po.Background.G)
|
||||
s.Require().Equal(uint8(130), po.Background.B)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathBackgroundHex() {
|
||||
path := "/background:ffddee/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.True(s.T(), po.Flatten)
|
||||
require.Equal(s.T(), uint8(0xff), po.Background.R)
|
||||
require.Equal(s.T(), uint8(0xdd), po.Background.G)
|
||||
require.Equal(s.T(), uint8(0xee), po.Background.B)
|
||||
s.Require().True(po.Flatten)
|
||||
s.Require().Equal(uint8(0xff), po.Background.R)
|
||||
s.Require().Equal(uint8(0xdd), po.Background.G)
|
||||
s.Require().Equal(uint8(0xee), po.Background.B)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathBackgroundDisable() {
|
||||
path := "/background:fff/background:/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.False(s.T(), po.Flatten)
|
||||
s.Require().False(po.Flatten)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathBlur() {
|
||||
path := "/blur:0.2/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), float32(0.2), po.Blur)
|
||||
s.Require().InDelta(float32(0.2), po.Blur, 0.0001)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathSharpen() {
|
||||
path := "/sharpen:0.2/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), float32(0.2), po.Sharpen)
|
||||
s.Require().InDelta(float32(0.2), po.Sharpen, 0.0001)
|
||||
}
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathDpr() {
|
||||
path := "/dpr:2/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), 2.0, po.Dpr)
|
||||
s.Require().InDelta(2.0, po.Dpr, 0.0001)
|
||||
}
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathWatermark() {
|
||||
path := "/watermark:0.5:soea:10:20:0.6/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.True(s.T(), po.Watermark.Enabled)
|
||||
require.Equal(s.T(), GravitySouthEast, po.Watermark.Gravity.Type)
|
||||
require.Equal(s.T(), 10.0, po.Watermark.Gravity.X)
|
||||
require.Equal(s.T(), 20.0, po.Watermark.Gravity.Y)
|
||||
require.Equal(s.T(), 0.6, po.Watermark.Scale)
|
||||
s.Require().True(po.Watermark.Enabled)
|
||||
s.Require().Equal(GravitySouthEast, po.Watermark.Gravity.Type)
|
||||
s.Require().InDelta(10.0, po.Watermark.Gravity.X, 0.0001)
|
||||
s.Require().InDelta(20.0, po.Watermark.Gravity.Y, 0.0001)
|
||||
s.Require().InDelta(0.6, po.Watermark.Scale, 0.0001)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathPreset() {
|
||||
@ -350,11 +349,11 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPreset() {
|
||||
path := "/preset:test1:test2/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), ResizeFill, po.ResizingType)
|
||||
require.Equal(s.T(), float32(0.2), po.Blur)
|
||||
require.Equal(s.T(), 50, po.Quality)
|
||||
s.Require().Equal(ResizeFill, po.ResizingType)
|
||||
s.Require().InDelta(float32(0.2), po.Blur, 0.0001)
|
||||
s.Require().Equal(50, po.Quality)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathPresetDefault() {
|
||||
@ -367,11 +366,11 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPresetDefault() {
|
||||
path := "/quality:70/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), ResizeFill, po.ResizingType)
|
||||
require.Equal(s.T(), float32(0.2), po.Blur)
|
||||
require.Equal(s.T(), 70, po.Quality)
|
||||
s.Require().Equal(ResizeFill, po.ResizingType)
|
||||
s.Require().InDelta(float32(0.2), po.Blur, 0.0001)
|
||||
s.Require().Equal(70, po.Quality)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathPresetLoopDetection() {
|
||||
@ -388,27 +387,27 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPresetLoopDetection() {
|
||||
path := "/preset:test1/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.ElementsMatch(s.T(), po.UsedPresets, []string{"test1", "test2"})
|
||||
s.Require().ElementsMatch(po.UsedPresets, []string{"test1", "test2"})
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathCachebuster() {
|
||||
path := "/cachebuster:123/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), "123", po.CacheBuster)
|
||||
s.Require().Equal("123", po.CacheBuster)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathStripMetadata() {
|
||||
path := "/strip_metadata:true/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.True(s.T(), po.StripMetadata)
|
||||
s.Require().True(po.StripMetadata)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathWebpDetection() {
|
||||
@ -418,10 +417,10 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWebpDetection() {
|
||||
headers := http.Header{"Accept": []string{"image/webp"}}
|
||||
po, _, err := ParsePath(path, headers)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), true, po.PreferWebP)
|
||||
require.Equal(s.T(), false, po.EnforceWebP)
|
||||
s.Require().True(po.PreferWebP)
|
||||
s.Require().False(po.EnforceWebP)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathWebpEnforce() {
|
||||
@ -431,10 +430,10 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWebpEnforce() {
|
||||
headers := http.Header{"Accept": []string{"image/webp"}}
|
||||
po, _, err := ParsePath(path, headers)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), true, po.PreferWebP)
|
||||
require.Equal(s.T(), true, po.EnforceWebP)
|
||||
s.Require().True(po.PreferWebP)
|
||||
s.Require().True(po.EnforceWebP)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeader() {
|
||||
@ -444,9 +443,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeader() {
|
||||
headers := http.Header{"Width": []string{"100"}}
|
||||
po, _, err := ParsePath(path, headers)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), 100, po.Width)
|
||||
s.Require().Equal(100, po.Width)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderDisabled() {
|
||||
@ -454,9 +453,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderDisabled() {
|
||||
headers := http.Header{"Width": []string{"100"}}
|
||||
po, _, err := ParsePath(path, headers)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), 0, po.Width)
|
||||
s.Require().Equal(0, po.Width)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderRedefine() {
|
||||
@ -466,9 +465,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderRedefine() {
|
||||
headers := http.Header{"Width": []string{"100"}}
|
||||
po, _, err := ParsePath(path, headers)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), 150, po.Width)
|
||||
s.Require().Equal(150, po.Width)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathDprHeader() {
|
||||
@ -478,9 +477,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePathDprHeader() {
|
||||
headers := http.Header{"Dpr": []string{"2"}}
|
||||
po, _, err := ParsePath(path, headers)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), 2.0, po.Dpr)
|
||||
s.Require().InDelta(2.0, po.Dpr, 0.0001)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathDprHeaderDisabled() {
|
||||
@ -488,32 +487,11 @@ func (s *ProcessingOptionsTestSuite) TestParsePathDprHeaderDisabled() {
|
||||
headers := http.Header{"Dpr": []string{"2"}}
|
||||
po, _, err := ParsePath(path, headers)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), 1.0, po.Dpr)
|
||||
s.Require().InDelta(1.0, po.Dpr, 0.0001)
|
||||
}
|
||||
|
||||
// func (s *ProcessingOptionsTestSuite) TestParsePathSigned() {
|
||||
// config.Keys = [][]byte{[]byte("test-key")}
|
||||
// config.Salts = [][]byte{[]byte("test-salt")}
|
||||
|
||||
// path := "/HcvNognEV1bW6f8zRqxNYuOkV0IUf1xloRb57CzbT4g/width:150/plain/http://images.dev/lorem/ipsum.jpg@png"
|
||||
// _, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
// require.Nil(s.T(), err)
|
||||
// }
|
||||
|
||||
// func (s *ProcessingOptionsTestSuite) TestParsePathSignedInvalid() {
|
||||
// config.Keys = [][]byte{[]byte("test-key")}
|
||||
// config.Salts = [][]byte{[]byte("test-salt")}
|
||||
|
||||
// path := "/unsafe/width:150/plain/http://images.dev/lorem/ipsum.jpg@png"
|
||||
// _, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
// require.Error(s.T(), err)
|
||||
// require.Equal(s.T(), signature.ErrInvalidSignature.Error(), err.Error())
|
||||
// }
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
|
||||
config.OnlyPresets = true
|
||||
presets["test1"] = urlOptions{
|
||||
@ -527,10 +505,10 @@ func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
|
||||
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), float32(0.2), po.Blur)
|
||||
require.Equal(s.T(), 50, po.Quality)
|
||||
s.Require().InDelta(float32(0.2), po.Blur, 0.0001)
|
||||
s.Require().Equal(50, po.Quality)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseSkipProcessing() {
|
||||
@ -538,9 +516,9 @@ func (s *ProcessingOptionsTestSuite) TestParseSkipProcessing() {
|
||||
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), []imagetype.Type{imagetype.JPEG, imagetype.PNG}, po.SkipProcessingFormats)
|
||||
s.Require().Equal([]imagetype.Type{imagetype.JPEG, imagetype.PNG}, po.SkipProcessingFormats)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseSkipProcessingInvalid() {
|
||||
@ -548,23 +526,23 @@ func (s *ProcessingOptionsTestSuite) TestParseSkipProcessingInvalid() {
|
||||
|
||||
_, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Error(s.T(), err)
|
||||
require.Equal(s.T(), "Invalid image format in skip processing: bad_format", err.Error())
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal("Invalid image format in skip processing: bad_format", err.Error())
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseExpires() {
|
||||
path := "/exp:32503669200/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
_, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseExpiresExpired() {
|
||||
path := "/exp:1609448400/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
_, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Error(s.T(), err)
|
||||
require.Equal(s.T(), errExpiredURL.Error(), err.Error())
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(errExpiredURL.Error(), err.Error())
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseBase64URLOnlyPresets() {
|
||||
@ -581,11 +559,11 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLOnlyPresets() {
|
||||
|
||||
po, imageURL, err := ParsePath(path, make(http.Header))
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.Equal(s.T(), float32(0.2), po.Blur)
|
||||
require.Equal(s.T(), 50, po.Quality)
|
||||
require.Equal(s.T(), originURL, imageURL)
|
||||
s.Require().InDelta(float32(0.2), po.Blur, 0.0001)
|
||||
s.Require().Equal(50, po.Quality)
|
||||
s.Require().Equal(originURL, imageURL)
|
||||
}
|
||||
|
||||
func TestProcessingOptions(t *testing.T) {
|
||||
|
@ -13,6 +13,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
"github.com/imgproxy/imgproxy/v3/config/configurators"
|
||||
"github.com/imgproxy/imgproxy/v3/etag"
|
||||
@ -23,9 +26,6 @@ import (
|
||||
"github.com/imgproxy/imgproxy/v3/router"
|
||||
"github.com/imgproxy/imgproxy/v3/svg"
|
||||
"github.com/imgproxy/imgproxy/v3/vips"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type ProcessingHandlerTestSuite struct {
|
||||
@ -38,14 +38,14 @@ func (s *ProcessingHandlerTestSuite) SetupSuite() {
|
||||
config.Reset()
|
||||
|
||||
wd, err := os.Getwd()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
config.LocalFileSystemRoot = filepath.Join(wd, "/testdata")
|
||||
// Disable keep-alive to test connection restrictions
|
||||
config.ClientKeepAliveTimeout = 0
|
||||
|
||||
err = initialize()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
logrus.SetOutput(io.Discard)
|
||||
|
||||
@ -79,17 +79,17 @@ func (s *ProcessingHandlerTestSuite) send(path string, header ...http.Header) *h
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) readTestFile(name string) []byte {
|
||||
wd, err := os.Getwd()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
data, err := os.ReadFile(filepath.Join(wd, "testdata", name))
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) readBody(res *http.Response) []byte {
|
||||
data, err := io.ReadAll(res.Body)
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
return data
|
||||
}
|
||||
|
||||
@ -121,15 +121,15 @@ func (s *ProcessingHandlerTestSuite) TestRequest() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Equal(s.T(), "image/png", res.Header.Get("Content-Type"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Equal("image/png", res.Header.Get("Content-Type"))
|
||||
|
||||
meta, err := imagemeta.DecodeMeta(res.Body)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), imagetype.PNG, meta.Format())
|
||||
require.Equal(s.T(), 4, meta.Width())
|
||||
require.Equal(s.T(), 4, meta.Height())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(imagetype.PNG, meta.Format())
|
||||
s.Require().Equal(4, meta.Width())
|
||||
s.Require().Equal(4, meta.Height())
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestSignatureValidationFailure() {
|
||||
@ -139,7 +139,7 @@ func (s *ProcessingHandlerTestSuite) TestSignatureValidationFailure() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 403, res.StatusCode)
|
||||
s.Require().Equal(403, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestSignatureValidationSuccess() {
|
||||
@ -149,7 +149,7 @@ func (s *ProcessingHandlerTestSuite) TestSignatureValidationSuccess() {
|
||||
rw := s.send("/My9d3xq_PYpVHsPrCyww0Kh1w5KZeZhIlWhsa4az1TI/rs:fill:4:4/plain/local:///test1.png")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestSourceValidation() {
|
||||
@ -195,7 +195,7 @@ func (s *ProcessingHandlerTestSuite) TestSourceValidation() {
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
s.T().Run(tc.name, func(t *testing.T) {
|
||||
s.Run(tc.name, func() {
|
||||
exps := make([]*regexp.Regexp, len(tc.allowedSources))
|
||||
for i, pattern := range tc.allowedSources {
|
||||
exps[i] = configurators.RegexpFromPattern(pattern)
|
||||
@ -206,9 +206,9 @@ func (s *ProcessingHandlerTestSuite) TestSourceValidation() {
|
||||
res := rw.Result()
|
||||
|
||||
if tc.expectedError {
|
||||
require.Equal(s.T(), 404, res.StatusCode)
|
||||
s.Require().Equal(404, res.StatusCode)
|
||||
} else {
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -229,11 +229,11 @@ func (s *ProcessingHandlerTestSuite) TestSourceNetworkValidation() {
|
||||
fmt.Println(u)
|
||||
|
||||
rw = s.send(u)
|
||||
require.Equal(s.T(), 200, rw.Result().StatusCode)
|
||||
s.Require().Equal(200, rw.Result().StatusCode)
|
||||
|
||||
config.AllowLoopbackSourceAddresses = false
|
||||
rw = s.send(u)
|
||||
require.Equal(s.T(), 404, rw.Result().StatusCode)
|
||||
s.Require().Equal(404, rw.Result().StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestSourceFormatNotSupported() {
|
||||
@ -243,7 +243,7 @@ func (s *ProcessingHandlerTestSuite) TestSourceFormatNotSupported() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 422, res.StatusCode)
|
||||
s.Require().Equal(422, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestResultingFormatNotSupported() {
|
||||
@ -253,7 +253,7 @@ func (s *ProcessingHandlerTestSuite) TestResultingFormatNotSupported() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@png")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 422, res.StatusCode)
|
||||
s.Require().Equal(422, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestSkipProcessingConfig() {
|
||||
@ -262,24 +262,24 @@ func (s *ProcessingHandlerTestSuite) TestSkipProcessingConfig() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
|
||||
actual := s.readBody(res)
|
||||
expected := s.readTestFile("test1.png")
|
||||
|
||||
require.True(s.T(), bytes.Equal(expected, actual))
|
||||
s.Require().True(bytes.Equal(expected, actual))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestSkipProcessingPO() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/skp:png/plain/local:///test1.png")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
|
||||
actual := s.readBody(res)
|
||||
expected := s.readTestFile("test1.png")
|
||||
|
||||
require.True(s.T(), bytes.Equal(expected, actual))
|
||||
s.Require().True(bytes.Equal(expected, actual))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestSkipProcessingSameFormat() {
|
||||
@ -288,12 +288,12 @@ func (s *ProcessingHandlerTestSuite) TestSkipProcessingSameFormat() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@png")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
|
||||
actual := s.readBody(res)
|
||||
expected := s.readTestFile("test1.png")
|
||||
|
||||
require.True(s.T(), bytes.Equal(expected, actual))
|
||||
s.Require().True(bytes.Equal(expected, actual))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestSkipProcessingDifferentFormat() {
|
||||
@ -302,45 +302,45 @@ func (s *ProcessingHandlerTestSuite) TestSkipProcessingDifferentFormat() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@jpg")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
|
||||
actual := s.readBody(res)
|
||||
expected := s.readTestFile("test1.png")
|
||||
|
||||
require.False(s.T(), bytes.Equal(expected, actual))
|
||||
s.Require().False(bytes.Equal(expected, actual))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestSkipProcessingSVG() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.svg")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
|
||||
actual := s.readBody(res)
|
||||
expected, err := svg.Sanitize(&imagedata.ImageData{Data: s.readTestFile("test1.svg")})
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
require.True(s.T(), bytes.Equal(expected.Data, actual))
|
||||
s.Require().True(bytes.Equal(expected.Data, actual))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestNotSkipProcessingSVGToJPG() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.svg@jpg")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
|
||||
actual := s.readBody(res)
|
||||
expected := s.readTestFile("test1.svg")
|
||||
|
||||
require.False(s.T(), bytes.Equal(expected, actual))
|
||||
s.Require().False(bytes.Equal(expected, actual))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestErrorSavingToSVG() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@svg")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 422, res.StatusCode)
|
||||
s.Require().Equal(422, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughCacheControl() {
|
||||
@ -357,8 +357,8 @@ func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughCacheControl() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), "max-age=1234, public", res.Header.Get("Cache-Control"))
|
||||
require.Empty(s.T(), res.Header.Get("Expires"))
|
||||
s.Require().Equal("max-age=1234, public", res.Header.Get("Cache-Control"))
|
||||
s.Require().Empty(res.Header.Get("Expires"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughExpires() {
|
||||
@ -375,8 +375,8 @@ func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughExpires() {
|
||||
res := rw.Result()
|
||||
|
||||
// Use regex to allow some delay
|
||||
require.Regexp(s.T(), regexp.MustCompile("max-age=123[0-9], public"), res.Header.Get("Cache-Control"))
|
||||
require.Empty(s.T(), res.Header.Get("Expires"))
|
||||
s.Require().Regexp(regexp.MustCompile("max-age=123[0-9], public"), res.Header.Get("Cache-Control"))
|
||||
s.Require().Empty(res.Header.Get("Expires"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughDisabled() {
|
||||
@ -393,8 +393,8 @@ func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughDisabled() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
|
||||
res := rw.Result()
|
||||
|
||||
require.NotEqual(s.T(), "max-age=1234, public", res.Header.Get("Cache-Control"))
|
||||
require.Empty(s.T(), res.Header.Get("Expires"))
|
||||
s.Require().NotEqual("max-age=1234, public", res.Header.Get("Cache-Control"))
|
||||
s.Require().Empty(res.Header.Get("Expires"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestETagDisabled() {
|
||||
@ -403,8 +403,8 @@ func (s *ProcessingHandlerTestSuite) TestETagDisabled() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Empty(s.T(), res.Header.Get("ETag"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Empty(res.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestETagReqNoIfNotModified() {
|
||||
@ -413,7 +413,7 @@ func (s *ProcessingHandlerTestSuite) TestETagReqNoIfNotModified() {
|
||||
poStr, imgdata, etag := s.sampleETagData("loremipsumdolor")
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
require.Empty(s.T(), r.Header.Get("If-None-Match"))
|
||||
s.Require().Empty(r.Header.Get("If-None-Match"))
|
||||
|
||||
rw.Header().Set("ETag", imgdata.Headers["ETag"])
|
||||
rw.WriteHeader(200)
|
||||
@ -424,8 +424,8 @@ func (s *ProcessingHandlerTestSuite) TestETagReqNoIfNotModified() {
|
||||
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL))
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Equal(s.T(), etag, res.Header.Get("ETag"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Equal(etag, res.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestETagDataNoIfNotModified() {
|
||||
@ -434,7 +434,7 @@ func (s *ProcessingHandlerTestSuite) TestETagDataNoIfNotModified() {
|
||||
poStr, imgdata, etag := s.sampleETagData("")
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
require.Empty(s.T(), r.Header.Get("If-None-Match"))
|
||||
s.Require().Empty(r.Header.Get("If-None-Match"))
|
||||
|
||||
rw.WriteHeader(200)
|
||||
rw.Write(imgdata.Data)
|
||||
@ -444,8 +444,8 @@ func (s *ProcessingHandlerTestSuite) TestETagDataNoIfNotModified() {
|
||||
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL))
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Equal(s.T(), etag, res.Header.Get("ETag"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Equal(etag, res.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestETagReqMatch() {
|
||||
@ -454,7 +454,7 @@ func (s *ProcessingHandlerTestSuite) TestETagReqMatch() {
|
||||
poStr, imgdata, etag := s.sampleETagData(`"loremipsumdolor"`)
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(s.T(), imgdata.Headers["ETag"], r.Header.Get("If-None-Match"))
|
||||
s.Require().Equal(imgdata.Headers["ETag"], r.Header.Get("If-None-Match"))
|
||||
|
||||
rw.WriteHeader(304)
|
||||
}))
|
||||
@ -466,8 +466,8 @@ func (s *ProcessingHandlerTestSuite) TestETagReqMatch() {
|
||||
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 304, res.StatusCode)
|
||||
require.Equal(s.T(), etag, res.Header.Get("ETag"))
|
||||
s.Require().Equal(304, res.StatusCode)
|
||||
s.Require().Equal(etag, res.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestETagDataMatch() {
|
||||
@ -476,7 +476,7 @@ func (s *ProcessingHandlerTestSuite) TestETagDataMatch() {
|
||||
poStr, imgdata, etag := s.sampleETagData("")
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
require.Empty(s.T(), r.Header.Get("If-None-Match"))
|
||||
s.Require().Empty(r.Header.Get("If-None-Match"))
|
||||
|
||||
rw.WriteHeader(200)
|
||||
rw.Write(imgdata.Data)
|
||||
@ -489,8 +489,8 @@ func (s *ProcessingHandlerTestSuite) TestETagDataMatch() {
|
||||
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 304, res.StatusCode)
|
||||
require.Equal(s.T(), etag, res.Header.Get("ETag"))
|
||||
s.Require().Equal(304, res.StatusCode)
|
||||
s.Require().Equal(etag, res.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestETagReqNotMatch() {
|
||||
@ -500,7 +500,7 @@ func (s *ProcessingHandlerTestSuite) TestETagReqNotMatch() {
|
||||
_, _, expectedETag := s.sampleETagData(`"loremipsum"`)
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(s.T(), `"loremipsum"`, r.Header.Get("If-None-Match"))
|
||||
s.Require().Equal(`"loremipsum"`, r.Header.Get("If-None-Match"))
|
||||
|
||||
rw.Header().Set("ETag", imgdata.Headers["ETag"])
|
||||
rw.WriteHeader(200)
|
||||
@ -514,8 +514,8 @@ func (s *ProcessingHandlerTestSuite) TestETagReqNotMatch() {
|
||||
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Equal(s.T(), actualETag, res.Header.Get("ETag"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Equal(actualETag, res.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestETagDataNotMatch() {
|
||||
@ -526,7 +526,7 @@ func (s *ProcessingHandlerTestSuite) TestETagDataNotMatch() {
|
||||
expectedETag := actualETag[:strings.IndexByte(actualETag, '/')] + "/Dasdbefj"
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
require.Empty(s.T(), r.Header.Get("If-None-Match"))
|
||||
s.Require().Empty(r.Header.Get("If-None-Match"))
|
||||
|
||||
rw.WriteHeader(200)
|
||||
rw.Write(imgdata.Data)
|
||||
@ -539,8 +539,8 @@ func (s *ProcessingHandlerTestSuite) TestETagDataNotMatch() {
|
||||
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Equal(s.T(), actualETag, res.Header.Get("ETag"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Equal(actualETag, res.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestETagProcessingOptionsNotMatch() {
|
||||
@ -551,7 +551,7 @@ func (s *ProcessingHandlerTestSuite) TestETagProcessingOptionsNotMatch() {
|
||||
expectedETag := "abcdefj" + actualETag[strings.IndexByte(actualETag, '/'):]
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
require.Empty(s.T(), r.Header.Get("If-None-Match"))
|
||||
s.Require().Empty(r.Header.Get("If-None-Match"))
|
||||
|
||||
rw.Header().Set("ETag", imgdata.Headers["ETag"])
|
||||
rw.WriteHeader(200)
|
||||
@ -565,8 +565,8 @@ func (s *ProcessingHandlerTestSuite) TestETagProcessingOptionsNotMatch() {
|
||||
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Equal(s.T(), actualETag, res.Header.Get("ETag"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Equal(actualETag, res.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestLastModifiedEnabled() {
|
||||
@ -581,7 +581,7 @@ func (s *ProcessingHandlerTestSuite) TestLastModifiedEnabled() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), "Wed, 21 Oct 2015 07:28:00 GMT", res.Header.Get("Last-Modified"))
|
||||
s.Require().Equal("Wed, 21 Oct 2015 07:28:00 GMT", res.Header.Get("Last-Modified"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestLastModifiedDisabled() {
|
||||
@ -596,7 +596,7 @@ func (s *ProcessingHandlerTestSuite) TestLastModifiedDisabled() {
|
||||
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), "", res.Header.Get("Last-Modified"))
|
||||
s.Require().Equal("", res.Header.Get("Last-Modified"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqExactMatchLastModifiedDisabled() {
|
||||
@ -605,7 +605,7 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqExactMatchLastModifiedD
|
||||
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")
|
||||
require.Equal(s.T(), "", modifiedSince)
|
||||
s.Require().Empty(modifiedSince)
|
||||
rw.WriteHeader(200)
|
||||
rw.Write(data)
|
||||
}))
|
||||
@ -616,7 +616,7 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqExactMatchLastModifiedD
|
||||
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqExactMatchLastModifiedEnabled() {
|
||||
@ -624,7 +624,7 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqExactMatchLastModifiedE
|
||||
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")
|
||||
require.Equal(s.T(), lastModified, modifiedSince)
|
||||
s.Require().Equal(lastModified, modifiedSince)
|
||||
rw.WriteHeader(304)
|
||||
}))
|
||||
defer ts.Close()
|
||||
@ -634,7 +634,7 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqExactMatchLastModifiedE
|
||||
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 304, res.StatusCode)
|
||||
s.Require().Equal(304, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareMoreRecentLastModifiedDisabled() {
|
||||
@ -642,7 +642,7 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareMoreRecentLastMo
|
||||
config.LastModifiedEnabled = false
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
modifiedSince := r.Header.Get("If-Modified-Since")
|
||||
require.Equal(s.T(), modifiedSince, "")
|
||||
s.Require().Empty(modifiedSince)
|
||||
rw.WriteHeader(200)
|
||||
rw.Write(data)
|
||||
}))
|
||||
@ -655,7 +655,7 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareMoreRecentLastMo
|
||||
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareMoreRecentLastModifiedEnabled() {
|
||||
@ -664,8 +664,8 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareMoreRecentLastMo
|
||||
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)
|
||||
require.Nil(s.T(), err)
|
||||
require.True(s.T(), fileLastModified.Before(parsedModifiedSince))
|
||||
s.Require().NoError(err)
|
||||
s.Require().True(fileLastModified.Before(parsedModifiedSince))
|
||||
rw.WriteHeader(304)
|
||||
}))
|
||||
defer ts.Close()
|
||||
@ -677,7 +677,7 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareMoreRecentLastMo
|
||||
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 304, res.StatusCode)
|
||||
s.Require().Equal(304, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareTooOldLastModifiedDisabled() {
|
||||
@ -685,7 +685,7 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareTooOldLastModifi
|
||||
data := s.readTestFile("test1.png")
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
modifiedSince := r.Header.Get("If-Modified-Since")
|
||||
require.Equal(s.T(), modifiedSince, "")
|
||||
s.Require().Empty(modifiedSince)
|
||||
rw.WriteHeader(200)
|
||||
rw.Write(data)
|
||||
}))
|
||||
@ -698,7 +698,7 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareTooOldLastModifi
|
||||
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareTooOldLastModifiedEnabled() {
|
||||
@ -708,8 +708,8 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareTooOldLastModifi
|
||||
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)
|
||||
require.Nil(s.T(), err)
|
||||
require.True(s.T(), fileLastModified.After(parsedModifiedSince))
|
||||
s.Require().NoError(err)
|
||||
s.Require().True(fileLastModified.After(parsedModifiedSince))
|
||||
rw.WriteHeader(200)
|
||||
rw.Write(data)
|
||||
}))
|
||||
@ -722,7 +722,7 @@ func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqCompareTooOldLastModifi
|
||||
rw := s.send(fmt.Sprintf("/unsafe/plain/%s", ts.URL), header)
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvg() {
|
||||
@ -731,8 +731,8 @@ func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvg() {
|
||||
rw := s.send("/unsafe/rs:fill:40:40/plain/local:///test1.svg")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Equal(s.T(), "image/png", res.Header.Get("Content-Type"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Equal("image/png", res.Header.Get("Content-Type"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvgWithEnforceAvif() {
|
||||
@ -742,8 +742,8 @@ func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvgWithEnforceAvif() {
|
||||
rw := s.send("/unsafe/plain/local:///test1.svg", http.Header{"Accept": []string{"image/webp"}})
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Equal(s.T(), "image/webp", res.Header.Get("Content-Type"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Equal("image/webp", res.Header.Get("Content-Type"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvgDisabled() {
|
||||
@ -753,8 +753,8 @@ func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvgDisabled() {
|
||||
rw := s.send("/unsafe/plain/local:///test1.svg")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Equal(s.T(), "image/svg+xml", res.Header.Get("Content-Type"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Equal("image/svg+xml", res.Header.Get("Content-Type"))
|
||||
}
|
||||
|
||||
func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvgWithFormat() {
|
||||
@ -763,8 +763,8 @@ func (s *ProcessingHandlerTestSuite) TestAlwaysRasterizeSvgWithFormat() {
|
||||
rw := s.send("/unsafe/plain/local:///test1.svg@svg")
|
||||
res := rw.Result()
|
||||
|
||||
require.Equal(s.T(), 200, res.StatusCode)
|
||||
require.Equal(s.T(), "image/svg+xml", res.Header.Get("Content-Type"))
|
||||
s.Require().Equal(200, res.StatusCode)
|
||||
s.Require().Equal("image/svg+xml", res.Header.Get("Content-Type"))
|
||||
}
|
||||
|
||||
func TestProcessingHandler(t *testing.T) {
|
||||
|
@ -3,7 +3,6 @@ package security
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
@ -22,19 +21,19 @@ func (s *SignatureTestSuite) SetupTest() {
|
||||
|
||||
func (s *SignatureTestSuite) TestVerifySignature() {
|
||||
err := VerifySignature("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *SignatureTestSuite) TestVerifySignatureTruncated() {
|
||||
config.SignatureSize = 8
|
||||
|
||||
err := VerifySignature("dtLwhdnPPis", "asd")
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *SignatureTestSuite) TestVerifySignatureInvalid() {
|
||||
err := VerifySignature("dtLwhdnPPis", "asd")
|
||||
require.Error(s.T(), err)
|
||||
s.Require().Error(err)
|
||||
}
|
||||
|
||||
func (s *SignatureTestSuite) TestVerifySignatureMultiplePairs() {
|
||||
@ -42,13 +41,13 @@ func (s *SignatureTestSuite) TestVerifySignatureMultiplePairs() {
|
||||
config.Salts = append(config.Salts, []byte("test-salt2"))
|
||||
|
||||
err := VerifySignature("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = VerifySignature("jbDffNPt1-XBgDccsaE-XJB9lx8JIJqdeYIZKgOqZpg", "asd")
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = VerifySignature("dtLwhdnPPis", "asd")
|
||||
require.Error(s.T(), err)
|
||||
s.Require().Error(err)
|
||||
}
|
||||
|
||||
func (s *SignatureTestSuite) TestVerifySignatureTrusted() {
|
||||
@ -58,10 +57,10 @@ func (s *SignatureTestSuite) TestVerifySignatureTrusted() {
|
||||
}()
|
||||
|
||||
err := VerifySignature("truested", "asd")
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = VerifySignature("untrusted", "asd")
|
||||
require.Error(s.T(), err)
|
||||
s.Require().Error(err)
|
||||
}
|
||||
|
||||
func TestSignature(t *testing.T) {
|
||||
|
@ -6,11 +6,11 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
"github.com/imgproxy/imgproxy/v3/imagedata"
|
||||
"github.com/imgproxy/imgproxy/v3/imagetype"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type SvgTestSuite struct {
|
||||
@ -21,15 +21,15 @@ func (s *SvgTestSuite) SetupSuite() {
|
||||
config.Reset()
|
||||
|
||||
err := imagedata.Init()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *SvgTestSuite) readTestFile(name string) *imagedata.ImageData {
|
||||
wd, err := os.Getwd()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
data, err := os.ReadFile(filepath.Join(wd, "..", "testdata", name))
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
return &imagedata.ImageData{
|
||||
Type: imagetype.SVG,
|
||||
@ -47,9 +47,9 @@ func (s *SvgTestSuite) TestSanitize() {
|
||||
|
||||
actual, err := Sanitize(origin)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), string(expected.Data), string(actual.Data))
|
||||
require.Equal(s.T(), origin.Headers, actual.Headers)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(string(expected.Data), string(actual.Data))
|
||||
s.Require().Equal(origin.Headers, actual.Headers)
|
||||
}
|
||||
|
||||
func (s *SvgTestSuite) TestFixUnsupportedDropShadow() {
|
||||
@ -62,10 +62,10 @@ func (s *SvgTestSuite) TestFixUnsupportedDropShadow() {
|
||||
re := regexp.MustCompile(`"ds(in|of)-.+?"`)
|
||||
actualData := re.ReplaceAllString(string(actual.Data), `"ds$1-test"`)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.True(s.T(), changed)
|
||||
require.Equal(s.T(), string(expected.Data), actualData)
|
||||
require.Equal(s.T(), origin.Headers, actual.Headers)
|
||||
s.Require().NoError(err)
|
||||
s.Require().True(changed)
|
||||
s.Require().Equal(string(expected.Data), actualData)
|
||||
s.Require().Equal(origin.Headers, actual.Headers)
|
||||
}
|
||||
|
||||
func (s *SvgTestSuite) TestFixUnsupportedNothingChanged() {
|
||||
@ -73,9 +73,9 @@ func (s *SvgTestSuite) TestFixUnsupportedNothingChanged() {
|
||||
|
||||
actual, changed, err := FixUnsupported(origin)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
require.False(s.T(), changed)
|
||||
require.Equal(s.T(), origin, actual)
|
||||
s.Require().NoError(err)
|
||||
s.Require().False(changed)
|
||||
s.Require().Equal(origin, actual)
|
||||
}
|
||||
|
||||
func TestSvg(t *testing.T) {
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
@ -34,7 +33,7 @@ func (s *AzureTestSuite) SetupSuite() {
|
||||
s.lastModified, _ = time.Parse(http.TimeFormat, "Wed, 21 Oct 2015 07:28:00 GMT")
|
||||
|
||||
s.server = httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(s.T(), "/test/foo/test.png", r.URL.Path)
|
||||
s.Require().Equal("/test/foo/test.png", r.URL.Path)
|
||||
|
||||
rw.Header().Set("Etag", s.etag)
|
||||
rw.Header().Set("Last-Modified", s.lastModified.Format(http.TimeFormat))
|
||||
@ -49,7 +48,7 @@ func (s *AzureTestSuite) SetupSuite() {
|
||||
|
||||
var err error
|
||||
s.transport, err = New()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *AzureTestSuite) TearDownSuite() {
|
||||
@ -62,8 +61,8 @@ func (s *AzureTestSuite) TestRoundTripWithETagDisabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "abs://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *AzureTestSuite) TestRoundTripWithETagEnabled() {
|
||||
@ -71,9 +70,9 @@ func (s *AzureTestSuite) TestRoundTripWithETagEnabled() {
|
||||
request, _ := http.NewRequest("GET", "abs://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
require.Equal(s.T(), s.etag, response.Header.Get("ETag"))
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
s.Require().Equal(s.etag, response.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *AzureTestSuite) TestRoundTripWithIfNoneMatchReturns304() {
|
||||
@ -83,8 +82,8 @@ func (s *AzureTestSuite) TestRoundTripWithIfNoneMatchReturns304() {
|
||||
request.Header.Set("If-None-Match", s.etag)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusNotModified, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusNotModified, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *AzureTestSuite) TestRoundTripWithUpdatedETagReturns200() {
|
||||
@ -94,8 +93,8 @@ func (s *AzureTestSuite) TestRoundTripWithUpdatedETagReturns200() {
|
||||
request.Header.Set("If-None-Match", s.etag+"_wrong")
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusOK, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusOK, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *AzureTestSuite) TestRoundTripWithLastModifiedDisabledReturns200() {
|
||||
@ -103,8 +102,8 @@ func (s *AzureTestSuite) TestRoundTripWithLastModifiedDisabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "abs://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *AzureTestSuite) TestRoundTripWithLastModifiedEnabled() {
|
||||
@ -112,9 +111,9 @@ func (s *AzureTestSuite) TestRoundTripWithLastModifiedEnabled() {
|
||||
request, _ := http.NewRequest("GET", "abs://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
require.Equal(s.T(), s.lastModified.Format(http.TimeFormat), response.Header.Get("Last-Modified"))
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
s.Require().Equal(s.lastModified.Format(http.TimeFormat), response.Header.Get("Last-Modified"))
|
||||
}
|
||||
|
||||
func (s *AzureTestSuite) TestRoundTripWithIfModifiedSinceReturns304() {
|
||||
@ -124,8 +123,8 @@ func (s *AzureTestSuite) TestRoundTripWithIfModifiedSinceReturns304() {
|
||||
request.Header.Set("If-Modified-Since", s.lastModified.Format(http.TimeFormat))
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusNotModified, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusNotModified, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *AzureTestSuite) TestRoundTripWithUpdatedLastModifiedReturns200() {
|
||||
@ -135,8 +134,8 @@ func (s *AzureTestSuite) TestRoundTripWithUpdatedLastModifiedReturns200() {
|
||||
request.Header.Set("If-Modified-Since", s.lastModified.Add(-24*time.Hour).Format(http.TimeFormat))
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusOK, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusOK, response.StatusCode)
|
||||
}
|
||||
func TestAzureTransport(t *testing.T) {
|
||||
suite.Run(t, new(AzureTestSuite))
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
@ -23,12 +22,12 @@ type FsTestSuite struct {
|
||||
|
||||
func (s *FsTestSuite) SetupSuite() {
|
||||
wd, err := os.Getwd()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
config.LocalFileSystemRoot = filepath.Join(wd, "..", "..", "testdata")
|
||||
|
||||
fi, err := os.Stat(filepath.Join(config.LocalFileSystemRoot, "test1.png"))
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.etag = BuildEtag("/test1.png", fi)
|
||||
s.modTime = fi.ModTime()
|
||||
@ -40,8 +39,8 @@ func (s *FsTestSuite) TestRoundTripWithETagDisabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "local:///test1.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *FsTestSuite) TestRoundTripWithETagEnabled() {
|
||||
@ -49,9 +48,9 @@ func (s *FsTestSuite) TestRoundTripWithETagEnabled() {
|
||||
request, _ := http.NewRequest("GET", "local:///test1.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
require.Equal(s.T(), s.etag, response.Header.Get("ETag"))
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
s.Require().Equal(s.etag, response.Header.Get("ETag"))
|
||||
}
|
||||
func (s *FsTestSuite) TestRoundTripWithIfNoneMatchReturns304() {
|
||||
config.ETagEnabled = true
|
||||
@ -60,8 +59,8 @@ func (s *FsTestSuite) TestRoundTripWithIfNoneMatchReturns304() {
|
||||
request.Header.Set("If-None-Match", s.etag)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusNotModified, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusNotModified, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *FsTestSuite) TestRoundTripWithUpdatedETagReturns200() {
|
||||
@ -71,16 +70,16 @@ func (s *FsTestSuite) TestRoundTripWithUpdatedETagReturns200() {
|
||||
request.Header.Set("If-None-Match", s.etag+"_wrong")
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusOK, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusOK, response.StatusCode)
|
||||
}
|
||||
func (s *FsTestSuite) TestRoundTripWithLastModifiedDisabledReturns200() {
|
||||
config.LastModifiedEnabled = false
|
||||
request, _ := http.NewRequest("GET", "local:///test1.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *FsTestSuite) TestRoundTripWithLastModifiedEnabledReturns200() {
|
||||
@ -88,9 +87,9 @@ func (s *FsTestSuite) TestRoundTripWithLastModifiedEnabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "local:///test1.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
require.Equal(s.T(), s.modTime.Format(http.TimeFormat), response.Header.Get("Last-Modified"))
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
s.Require().Equal(s.modTime.Format(http.TimeFormat), response.Header.Get("Last-Modified"))
|
||||
}
|
||||
|
||||
func (s *FsTestSuite) TestRoundTripWithIfModifiedSinceReturns304() {
|
||||
@ -100,8 +99,8 @@ func (s *FsTestSuite) TestRoundTripWithIfModifiedSinceReturns304() {
|
||||
request.Header.Set("If-Modified-Since", s.modTime.Format(http.TimeFormat))
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusNotModified, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusNotModified, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *FsTestSuite) TestRoundTripWithUpdatedLastModifiedReturns200() {
|
||||
@ -111,8 +110,8 @@ func (s *FsTestSuite) TestRoundTripWithUpdatedLastModifiedReturns200() {
|
||||
request.Header.Set("If-Modified-Since", s.modTime.Add(-time.Minute).Format(http.TimeFormat))
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusOK, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusOK, response.StatusCode)
|
||||
}
|
||||
func TestS3Transport(t *testing.T) {
|
||||
suite.Run(t, new(FsTestSuite))
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fsouza/fake-gcs-server/fakestorage"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
@ -44,7 +43,7 @@ func (s *GCSTestSuite) SetupSuite() {
|
||||
s.lastModified, _ = time.Parse(http.TimeFormat, "Wed, 21 Oct 2015 07:28:00 GMT")
|
||||
|
||||
port, err := getFreePort()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.server, err = fakestorage.NewServerWithOptions(fakestorage.Options{
|
||||
Scheme: "http",
|
||||
@ -62,17 +61,17 @@ func (s *GCSTestSuite) SetupSuite() {
|
||||
},
|
||||
},
|
||||
})
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
obj, err := s.server.GetObject("test", "foo/test.png")
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
s.etag = obj.Etag
|
||||
|
||||
config.GCSEnabled = true
|
||||
config.GCSEndpoint = s.server.PublicURL() + "/storage/v1/"
|
||||
|
||||
s.transport, err = New()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *GCSTestSuite) TearDownSuite() {
|
||||
@ -84,8 +83,8 @@ func (s *GCSTestSuite) TestRoundTripWithETagDisabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "gcs://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *GCSTestSuite) TestRoundTripWithETagEnabled() {
|
||||
@ -93,9 +92,9 @@ func (s *GCSTestSuite) TestRoundTripWithETagEnabled() {
|
||||
request, _ := http.NewRequest("GET", "gcs://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
require.Equal(s.T(), s.etag, response.Header.Get("ETag"))
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
s.Require().Equal(s.etag, response.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *GCSTestSuite) TestRoundTripWithIfNoneMatchReturns304() {
|
||||
@ -105,8 +104,8 @@ func (s *GCSTestSuite) TestRoundTripWithIfNoneMatchReturns304() {
|
||||
request.Header.Set("If-None-Match", s.etag)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusNotModified, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusNotModified, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *GCSTestSuite) TestRoundTripWithUpdatedETagReturns200() {
|
||||
@ -116,8 +115,8 @@ func (s *GCSTestSuite) TestRoundTripWithUpdatedETagReturns200() {
|
||||
request.Header.Set("If-None-Match", s.etag+"_wrong")
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusOK, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusOK, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *GCSTestSuite) TestRoundTripWithLastModifiedDisabledReturns200() {
|
||||
@ -125,17 +124,17 @@ func (s *GCSTestSuite) TestRoundTripWithLastModifiedDisabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "gcs://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
func (s *GCSTestSuite) TestRoundTripWithLastModifiedEnabled() {
|
||||
config.LastModifiedEnabled = true
|
||||
request, _ := http.NewRequest("GET", "gcs://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
require.Equal(s.T(), s.lastModified.Format(http.TimeFormat), response.Header.Get("Last-Modified"))
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
s.Require().Equal(s.lastModified.Format(http.TimeFormat), response.Header.Get("Last-Modified"))
|
||||
}
|
||||
func (s *GCSTestSuite) TestRoundTripWithIfModifiedSinceReturns304() {
|
||||
config.LastModifiedEnabled = true
|
||||
@ -144,8 +143,8 @@ func (s *GCSTestSuite) TestRoundTripWithIfModifiedSinceReturns304() {
|
||||
request.Header.Set("If-Modified-Since", s.lastModified.Format(http.TimeFormat))
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusNotModified, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusNotModified, response.StatusCode)
|
||||
}
|
||||
func (s *GCSTestSuite) TestRoundTripWithUpdatedLastModifiedReturns200() {
|
||||
config.LastModifiedEnabled = true
|
||||
@ -154,8 +153,8 @@ func (s *GCSTestSuite) TestRoundTripWithUpdatedLastModifiedReturns200() {
|
||||
request.Header.Set("If-Modified-Sicne", s.lastModified.Add(-24*time.Hour).Format(http.TimeFormat))
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusOK, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusOK, response.StatusCode)
|
||||
}
|
||||
func TestGCSTransport(t *testing.T) {
|
||||
suite.Run(t, new(GCSTestSuite))
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/johannesboyne/gofakes3"
|
||||
"github.com/johannesboyne/gofakes3/backend/s3mem"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
@ -42,15 +41,15 @@ func (s *S3TestSuite) SetupSuite() {
|
||||
|
||||
var err error
|
||||
s.transport, err = New()
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = backend.CreateBucket("test")
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
svc, err := s.transport.(*transport).getClient(context.Background(), "test")
|
||||
require.Nil(s.T(), err)
|
||||
require.NotNil(s.T(), svc)
|
||||
require.IsType(s.T(), &s3.Client{}, svc)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(svc)
|
||||
s.Require().IsType(&s3.Client{}, svc)
|
||||
|
||||
client := svc.(*s3.Client)
|
||||
|
||||
@ -59,13 +58,13 @@ func (s *S3TestSuite) SetupSuite() {
|
||||
Bucket: aws.String("test"),
|
||||
Key: aws.String("foo/test.png"),
|
||||
})
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
|
||||
obj, err := client.GetObject(context.Background(), &s3.GetObjectInput{
|
||||
Bucket: aws.String("test"),
|
||||
Key: aws.String("foo/test.png"),
|
||||
})
|
||||
require.Nil(s.T(), err)
|
||||
s.Require().NoError(err)
|
||||
defer obj.Body.Close()
|
||||
|
||||
s.etag = *obj.ETag
|
||||
@ -82,8 +81,8 @@ func (s *S3TestSuite) TestRoundTripWithETagDisabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "s3://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *S3TestSuite) TestRoundTripWithETagEnabled() {
|
||||
@ -91,9 +90,9 @@ func (s *S3TestSuite) TestRoundTripWithETagEnabled() {
|
||||
request, _ := http.NewRequest("GET", "s3://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
require.Equal(s.T(), s.etag, response.Header.Get("ETag"))
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
s.Require().Equal(s.etag, response.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *S3TestSuite) TestRoundTripWithIfNoneMatchReturns304() {
|
||||
@ -103,8 +102,8 @@ func (s *S3TestSuite) TestRoundTripWithIfNoneMatchReturns304() {
|
||||
request.Header.Set("If-None-Match", s.etag)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusNotModified, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusNotModified, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *S3TestSuite) TestRoundTripWithUpdatedETagReturns200() {
|
||||
@ -114,8 +113,8 @@ func (s *S3TestSuite) TestRoundTripWithUpdatedETagReturns200() {
|
||||
request.Header.Set("If-None-Match", s.etag+"_wrong")
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusOK, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusOK, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *S3TestSuite) TestRoundTripWithLastModifiedDisabledReturns200() {
|
||||
@ -123,8 +122,8 @@ func (s *S3TestSuite) TestRoundTripWithLastModifiedDisabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "s3://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *S3TestSuite) TestRoundTripWithLastModifiedEnabled() {
|
||||
@ -132,9 +131,9 @@ func (s *S3TestSuite) TestRoundTripWithLastModifiedEnabled() {
|
||||
request, _ := http.NewRequest("GET", "s3://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
require.Equal(s.T(), s.lastModified.Format(http.TimeFormat), response.Header.Get("Last-Modified"))
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
s.Require().Equal(s.lastModified.Format(http.TimeFormat), response.Header.Get("Last-Modified"))
|
||||
}
|
||||
|
||||
func (s *S3TestSuite) TestRoundTripWithIfModifiedSinceReturns304() {
|
||||
@ -144,8 +143,8 @@ func (s *S3TestSuite) TestRoundTripWithIfModifiedSinceReturns304() {
|
||||
request.Header.Set("If-Modified-Since", s.lastModified.Format(http.TimeFormat))
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusNotModified, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusNotModified, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *S3TestSuite) TestRoundTripWithUpdatedLastModifiedReturns200() {
|
||||
@ -155,8 +154,8 @@ func (s *S3TestSuite) TestRoundTripWithUpdatedLastModifiedReturns200() {
|
||||
request.Header.Set("If-Modified-Since", s.lastModified.Add(-24*time.Hour).Format(http.TimeFormat))
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusOK, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusOK, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *S3TestSuite) TestRoundTripWithMultiregionEnabledReturns200() {
|
||||
@ -164,8 +163,8 @@ func (s *S3TestSuite) TestRoundTripWithMultiregionEnabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "s3://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
|
||||
func TestS3Transport(t *testing.T) {
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/ncw/swift/v2"
|
||||
"github.com/ncw/swift/v2/swifttest"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
@ -41,11 +40,10 @@ func (s *SwiftTestSuite) SetupSuite() {
|
||||
|
||||
var err error
|
||||
s.transport, err = New()
|
||||
require.Nil(s.T(), err, "failed to initialize swift transport")
|
||||
s.Require().NoError(err, "failed to initialize swift transport")
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) setupTestFile() {
|
||||
t := s.T()
|
||||
c := &swift.Connection{
|
||||
UserName: config.SwiftUsername,
|
||||
ApiKey: config.SwiftAPIKey,
|
||||
@ -56,29 +54,29 @@ func (s *SwiftTestSuite) setupTestFile() {
|
||||
ctx := context.Background()
|
||||
|
||||
err := c.Authenticate(ctx)
|
||||
require.Nil(t, err, "failed to authenticate with test server")
|
||||
s.Require().NoError(err, "failed to authenticate with test server")
|
||||
|
||||
err = c.ContainerCreate(ctx, testContainer, nil)
|
||||
require.Nil(t, err, "failed to create container")
|
||||
s.Require().NoError(err, "failed to create container")
|
||||
|
||||
f, err := c.ObjectCreate(ctx, testContainer, testObject, true, "", "image/png", nil)
|
||||
require.Nil(t, err, "failed to create object")
|
||||
s.Require().NoError(err, "failed to create object")
|
||||
|
||||
defer f.Close()
|
||||
|
||||
data := make([]byte, 32)
|
||||
|
||||
n, err := f.Write(data)
|
||||
require.Equal(t, n, len(data))
|
||||
require.Nil(t, err)
|
||||
s.Require().Len(data, n)
|
||||
s.Require().NoError(err)
|
||||
|
||||
f.Close()
|
||||
// The Etag is written on file close; but Last-Modified is only available when we get the object again.
|
||||
_, h, err := c.Object(ctx, testContainer, testObject)
|
||||
require.Nil(t, err)
|
||||
s.Require().NoError(err)
|
||||
s.etag = h["Etag"]
|
||||
s.lastModified, err = time.Parse(http.TimeFormat, h["Date"])
|
||||
require.Nil(t, err)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TearDownSuite() {
|
||||
@ -90,8 +88,8 @@ func (s *SwiftTestSuite) TestRoundTripWithETagDisabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "swift://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripReturns404WhenObjectNotFound() {
|
||||
@ -99,8 +97,8 @@ func (s *SwiftTestSuite) TestRoundTripReturns404WhenObjectNotFound() {
|
||||
request, _ := http.NewRequest("GET", "swift://test/foo/not-here.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 404, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(404, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripReturns404WhenContainerNotFound() {
|
||||
@ -108,8 +106,8 @@ func (s *SwiftTestSuite) TestRoundTripReturns404WhenContainerNotFound() {
|
||||
request, _ := http.NewRequest("GET", "swift://invalid/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 404, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(404, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripWithETagEnabled() {
|
||||
@ -117,9 +115,9 @@ func (s *SwiftTestSuite) TestRoundTripWithETagEnabled() {
|
||||
request, _ := http.NewRequest("GET", "swift://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
require.Equal(s.T(), s.etag, response.Header.Get("ETag"))
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
s.Require().Equal(s.etag, response.Header.Get("ETag"))
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripWithIfNoneMatchReturns304() {
|
||||
@ -129,8 +127,8 @@ func (s *SwiftTestSuite) TestRoundTripWithIfNoneMatchReturns304() {
|
||||
request.Header.Set("If-None-Match", s.etag)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusNotModified, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusNotModified, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripWithUpdatedETagReturns200() {
|
||||
@ -140,8 +138,8 @@ func (s *SwiftTestSuite) TestRoundTripWithUpdatedETagReturns200() {
|
||||
request.Header.Set("If-None-Match", s.etag+"_wrong")
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusOK, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusOK, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripWithLastModifiedDisabledReturns200() {
|
||||
@ -149,8 +147,8 @@ func (s *SwiftTestSuite) TestRoundTripWithLastModifiedDisabledReturns200() {
|
||||
request, _ := http.NewRequest("GET", "swift://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripWithLastModifiedEnabled() {
|
||||
@ -158,9 +156,9 @@ func (s *SwiftTestSuite) TestRoundTripWithLastModifiedEnabled() {
|
||||
request, _ := http.NewRequest("GET", "swift://test/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
require.Equal(s.T(), s.lastModified.Format(http.TimeFormat), response.Header.Get("Last-Modified"))
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(200, response.StatusCode)
|
||||
s.Require().Equal(s.lastModified.Format(http.TimeFormat), response.Header.Get("Last-Modified"))
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripWithIfModifiedSinceReturns304() {
|
||||
@ -170,8 +168,8 @@ func (s *SwiftTestSuite) TestRoundTripWithIfModifiedSinceReturns304() {
|
||||
request.Header.Set("If-Modified-Since", s.lastModified.Format(http.TimeFormat))
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusNotModified, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusNotModified, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripWithUpdatedLastModifiedReturns200() {
|
||||
@ -181,8 +179,8 @@ func (s *SwiftTestSuite) TestRoundTripWithUpdatedLastModifiedReturns200() {
|
||||
request.Header.Set("If-Modified-Since", s.lastModified.Add(-24*time.Hour).Format(http.TimeFormat))
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), http.StatusOK, response.StatusCode)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(http.StatusOK, response.StatusCode)
|
||||
}
|
||||
|
||||
func TestSwiftTransport(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user