This commit is contained in:
DarthSim
2018-11-06 17:19:34 +06:00
parent e1f3f4278b
commit 6b7551213f
18 changed files with 3164 additions and 110 deletions

View File

@@ -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))
}