crypt_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/suite"
  6. )
  7. type CryptTestSuite struct{ MainTestSuite }
  8. func (s *CryptTestSuite) SetupTest() {
  9. s.MainTestSuite.SetupTest()
  10. conf.Keys = []securityKey{securityKey("test-key")}
  11. conf.Salts = []securityKey{securityKey("test-salt")}
  12. }
  13. func (s *CryptTestSuite) TestValidatePath() {
  14. err := validatePath("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
  15. assert.Nil(s.T(), err)
  16. }
  17. func (s *CryptTestSuite) TestValidatePathTruncated() {
  18. conf.SignatureSize = 8
  19. err := validatePath("dtLwhdnPPis", "asd")
  20. assert.Nil(s.T(), err)
  21. }
  22. func (s *CryptTestSuite) TestValidatePathInvalid() {
  23. err := validatePath("dtLwhdnPPis", "asd")
  24. assert.Error(s.T(), err)
  25. }
  26. func (s *CryptTestSuite) TestValidatePathMultiplePairs() {
  27. conf.Keys = append(conf.Keys, securityKey("test-key2"))
  28. conf.Salts = append(conf.Salts, securityKey("test-salt2"))
  29. err := validatePath("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
  30. assert.Nil(s.T(), err)
  31. err = validatePath("jbDffNPt1-XBgDccsaE-XJB9lx8JIJqdeYIZKgOqZpg", "asd")
  32. assert.Nil(s.T(), err)
  33. err = validatePath("dtLwhdnPPis", "asd")
  34. assert.Error(s.T(), err)
  35. }
  36. func TestCrypt(t *testing.T) {
  37. suite.Run(t, new(CryptTestSuite))
  38. }