mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-09 19:52:30 +02:00
Tests
This commit is contained in:
@@ -1,22 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
func TestSignatureFor(t *testing.T) {
|
||||
oldConf := conf
|
||||
defer func() { conf = oldConf }()
|
||||
type CryptTestSuite struct{ MainTestSuite }
|
||||
|
||||
func (s *CryptTestSuite) SetupTest() {
|
||||
s.MainTestSuite.SetupTest()
|
||||
|
||||
base64Signature := func(x string) string { return base64.RawURLEncoding.EncodeToString(signatureFor(x)) }
|
||||
conf.Key = []byte("test-key")
|
||||
conf.Salt = []byte("test-salt")
|
||||
assert.Equal(t, "dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", base64Signature("asd"))
|
||||
assert.Equal(t, "8x1xvzxVqZ3Uz3kEC8gVvBfU0dfU1vKv0Gho8m3Ysgw", base64Signature("qwe"))
|
||||
conf.SignatureSize = 8
|
||||
assert.Equal(t, "dtLwhdnPPis", base64Signature("asd"))
|
||||
assert.Equal(t, "8x1xvzxVqZ0", base64Signature("qwe"))
|
||||
}
|
||||
|
||||
func (s *CryptTestSuite) TestValidatePath() {
|
||||
err := validatePath("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
|
||||
assert.Nil(s.T(), err)
|
||||
}
|
||||
|
||||
func (s *CryptTestSuite) TestValidatePathTruncated() {
|
||||
conf.SignatureSize = 8
|
||||
|
||||
err := validatePath("dtLwhdnPPis", "asd")
|
||||
assert.Nil(s.T(), err)
|
||||
}
|
||||
|
||||
func (s *CryptTestSuite) TestValidatePathInvalid() {
|
||||
err := validatePath("dtLwhdnPPis", "asd")
|
||||
assert.Error(s.T(), err)
|
||||
}
|
||||
|
||||
func TestCrypt(t *testing.T) {
|
||||
suite.Run(t, new(CryptTestSuite))
|
||||
}
|
||||
|
Reference in New Issue
Block a user