-
Notifications
You must be signed in to change notification settings - Fork 0
/
v1loc_test.go
46 lines (37 loc) · 982 Bytes
/
v1loc_test.go
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
41
42
43
44
45
46
package paseto
import (
"encoding/hex"
"strings"
"testing"
)
func TestV1Loc_Encrypt(t *testing.T) {
testCases := loadGoldenFile("testdata/v1.json")
for _, tc := range testCases.Tests {
if tc.Key == "" || !strings.HasPrefix(tc.Token, v1locHeader) {
continue
}
t.Run(tc.Name, func(t *testing.T) {
key := must(hex.DecodeString(tc.Key))
payload := mustJSON(tc.Payload)
footer := mustJSON(tc.Footer)
nonce := must(hex.DecodeString(tc.Nonce))
token, err := V1Encrypt(key, payload, footer, nonce)
mustOk(t, err)
mustEqual(t, token, tc.Token)
})
}
}
func TestV1Loc_Decrypt(t *testing.T) {
testCases := loadGoldenFile("testdata/v1.json")
for _, tc := range testCases.Tests {
if tc.Key == "" || !strings.HasPrefix(tc.Token, v1locHeader) {
continue
}
t.Run(tc.Name, func(t *testing.T) {
key := must(hex.DecodeString(tc.Key))
var payload, footer any
err := V1Decrypt(tc.Token, key, payload, footer)
mustOk(t, err)
})
}
}