Varakh
66800d26df
Reviewed-on: #22 Co-authored-by: Varakh <varakh@varakh.de> Co-committed-by: Varakh <varakh@varakh.de>
37 lines
704 B
Go
37 lines
704 B
Go
package util
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestEncryptsAndDecrypts(t *testing.T) {
|
|
a := assert.New(t)
|
|
|
|
testSecret := "mysecretpassword"
|
|
testText := "the super secret text"
|
|
|
|
encrypted, err := EncryptAndEncode(testText, testSecret)
|
|
a.Nil(err)
|
|
a.NotEmpty(encrypted)
|
|
a.NotEqual(testText, encrypted)
|
|
|
|
decrypted, err := DecryptAndDecode(encrypted, testSecret)
|
|
a.Nil(err)
|
|
a.Equal(testText, decrypted)
|
|
}
|
|
|
|
func TestEncodeAndDecode(t *testing.T) {
|
|
a := assert.New(t)
|
|
|
|
s := "my to be encoded value"
|
|
|
|
encoded, err := ConvertToBase64([]byte(s))
|
|
a.Nil(err)
|
|
a.NotEmpty(encoded)
|
|
|
|
decoded, err := ConvertFromBase64(encoded)
|
|
a.Nil(err)
|
|
a.Equal(s, string(decoded))
|
|
|
|
}
|