-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv2loc_test.go
48 lines (39 loc) · 975 Bytes
/
v2loc_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
47
48
package paseto
import (
"encoding/hex"
"strings"
"testing"
)
func TestV2Loc_Encrypt(t *testing.T) {
testCases := loadGoldenFile("testdata/v2.json")
for _, tc := range testCases.Tests {
if tc.Key == "" || !strings.HasPrefix(tc.Token, v2locHeader) {
continue
}
t.Run(tc.Name, func(t *testing.T) {
key := mustHex(tc.Key)
payload := mustJSON(tc.Payload)
footer := mustJSON(tc.Footer)
nonce := mustHex(tc.Nonce)
token, err := V2Encrypt(key, payload, footer, nonce)
if err != nil {
t.Fatal(err)
}
mustEqual(t, token, tc.Token)
})
}
}
func TestV2Loc_Decrypt(t *testing.T) {
testCases := loadGoldenFile("testdata/v2.json")
for _, tc := range testCases.Tests {
if tc.Key == "" || !strings.HasPrefix(tc.Token, v2locHeader) {
continue
}
t.Run(tc.Name, func(t *testing.T) {
key := must(hex.DecodeString(tc.Key))
var payload, footer any
err := V2Decrypt(tc.Token, key, payload, footer)
mustOk(t, err)
})
}
}