mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-29 08:22:11 +02:00
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package security
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/imgproxy/imgproxy/v3/config"
|
|
)
|
|
|
|
type SignatureTestSuite struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func (s *SignatureTestSuite) SetupTest() {
|
|
config.Reset()
|
|
|
|
config.Keys = [][]byte{[]byte("test-key")}
|
|
config.Salts = [][]byte{[]byte("test-salt")}
|
|
}
|
|
|
|
func (s *SignatureTestSuite) TestVerifySignature() {
|
|
err := VerifySignature("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
|
|
require.Nil(s.T(), err)
|
|
}
|
|
|
|
func (s *SignatureTestSuite) TestVerifySignatureTruncated() {
|
|
config.SignatureSize = 8
|
|
|
|
err := VerifySignature("dtLwhdnPPis", "asd")
|
|
require.Nil(s.T(), err)
|
|
}
|
|
|
|
func (s *SignatureTestSuite) TestVerifySignatureInvalid() {
|
|
err := VerifySignature("dtLwhdnPPis", "asd")
|
|
require.Error(s.T(), err)
|
|
}
|
|
|
|
func (s *SignatureTestSuite) TestVerifySignatureMultiplePairs() {
|
|
config.Keys = append(config.Keys, []byte("test-key2"))
|
|
config.Salts = append(config.Salts, []byte("test-salt2"))
|
|
|
|
err := VerifySignature("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
|
|
require.Nil(s.T(), err)
|
|
|
|
err = VerifySignature("jbDffNPt1-XBgDccsaE-XJB9lx8JIJqdeYIZKgOqZpg", "asd")
|
|
require.Nil(s.T(), err)
|
|
|
|
err = VerifySignature("dtLwhdnPPis", "asd")
|
|
require.Error(s.T(), err)
|
|
}
|
|
|
|
func TestSignature(t *testing.T) {
|
|
suite.Run(t, new(SignatureTestSuite))
|
|
}
|