2018-11-02 13:10:20 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-11-06 13:19:34 +02:00
|
|
|
"github.com/stretchr/testify/suite"
|
2018-11-02 13:10:20 +02:00
|
|
|
)
|
|
|
|
|
2018-11-06 13:19:34 +02:00
|
|
|
type CryptTestSuite struct{ MainTestSuite }
|
|
|
|
|
|
|
|
func (s *CryptTestSuite) SetupTest() {
|
|
|
|
s.MainTestSuite.SetupTest()
|
2018-11-02 17:35:21 +02:00
|
|
|
|
2018-11-15 14:35:06 +02:00
|
|
|
conf.Keys = []securityKey{securityKey("test-key")}
|
|
|
|
conf.Salts = []securityKey{securityKey("test-salt")}
|
2018-11-06 13:19:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *CryptTestSuite) TestValidatePath() {
|
|
|
|
err := validatePath("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
|
|
|
|
assert.Nil(s.T(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *CryptTestSuite) TestValidatePathTruncated() {
|
2018-11-02 13:10:20 +02:00
|
|
|
conf.SignatureSize = 8
|
2018-11-06 13:19:34 +02:00
|
|
|
|
|
|
|
err := validatePath("dtLwhdnPPis", "asd")
|
|
|
|
assert.Nil(s.T(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *CryptTestSuite) TestValidatePathInvalid() {
|
|
|
|
err := validatePath("dtLwhdnPPis", "asd")
|
|
|
|
assert.Error(s.T(), err)
|
|
|
|
}
|
|
|
|
|
2018-11-15 14:35:06 +02:00
|
|
|
func (s *CryptTestSuite) TestValidatePathMultiplePairs() {
|
|
|
|
conf.Keys = append(conf.Keys, securityKey("test-key2"))
|
|
|
|
conf.Salts = append(conf.Salts, securityKey("test-salt2"))
|
|
|
|
|
|
|
|
err := validatePath("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
|
|
|
|
assert.Nil(s.T(), err)
|
|
|
|
|
|
|
|
err = validatePath("jbDffNPt1-XBgDccsaE-XJB9lx8JIJqdeYIZKgOqZpg", "asd")
|
|
|
|
assert.Nil(s.T(), err)
|
|
|
|
|
|
|
|
err = validatePath("dtLwhdnPPis", "asd")
|
|
|
|
assert.Error(s.T(), err)
|
|
|
|
}
|
|
|
|
|
2018-11-06 13:19:34 +02:00
|
|
|
func TestCrypt(t *testing.T) {
|
|
|
|
suite.Run(t, new(CryptTestSuite))
|
2018-11-02 13:10:20 +02:00
|
|
|
}
|