-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcommon_test.go
More file actions
40 lines (30 loc) · 936 Bytes
/
common_test.go
File metadata and controls
40 lines (30 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestCommon(t *testing.T) {
t.Parallel()
ts := &TestSuite{}
config := testConfig()
ts.Setup(config)
defer ts.Teardown()
t.Run("AEAD encrypt/decrypt", ts.testAEADEncryptDecrypt)
t.Run("Encrypt/decrypt cookie value", ts.testEncryptDecryptCookieValue)
}
func (ts *TestSuite) testAEADEncryptDecrypt(t *testing.T) {
plaintext := []byte("I am a cookie value")
ciphertext, err := ts.App.AEADEncrypt(plaintext)
assert.Nil(t, err)
decrypted, err := ts.App.AEADDecrypt(ciphertext)
assert.Nil(t, err)
assert.Equal(t, plaintext, decrypted)
}
func (ts *TestSuite) testEncryptDecryptCookieValue(t *testing.T) {
plaintext := "I am a cookie value"
ciphertext, err := ts.App.EncryptCookieValue(plaintext)
assert.Nil(t, err)
decrypted, err := ts.App.DecryptCookieValue(ciphertext)
assert.Nil(t, err)
assert.Equal(t, plaintext, string(decrypted))
}