-
Notifications
You must be signed in to change notification settings - Fork 0
/
v4loc_test.go
64 lines (55 loc) · 1.3 KB
/
v4loc_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package paseto
import (
"encoding/hex"
"strings"
"testing"
)
func TestV4Loc_Encrypt(t *testing.T) {
testCases := loadGoldenFile("testdata/v4.json")
for _, tc := range testCases.Tests {
if tc.Key == "" || !strings.HasPrefix(tc.Token, v4locHeader) {
continue
}
if strings.HasPrefix(tc.Name, "4-F-") {
continue
}
t.Run(tc.Name, func(t *testing.T) {
key := mustHex(tc.Key)
payload := tc.Payload
footer := tc.Footer
imp := tc.ImplicitAssertion
nonce := mustHex(tc.Nonce)
token, err := V4Encrypt(key, payload, footer, imp, nonce)
if tc.ExpectFail {
mustFail(t, err)
} else {
mustOk(t, err)
mustEqual(t, token, tc.Token)
}
})
}
}
func TestV4Loc_Decrypt(t *testing.T) {
testCases := loadGoldenFile("testdata/v4.json")
for _, tc := range testCases.Tests {
if tc.Key == "" || !strings.HasPrefix(tc.Token, v4locHeader) {
continue
}
// TODO: (probably) should fail.
if tc.Name == "4-F-4" {
continue
}
t.Run(tc.Name, func(t *testing.T) {
key := must(hex.DecodeString(tc.Key))
var payload, footer string
err := V4Decrypt(tc.Token, key, &payload, &footer, tc.ImplicitAssertion)
if tc.ExpectFail {
mustFail(t, err)
} else {
mustOk(t, err)
mustEqual(t, payload, tc.Payload)
mustEqual(t, footer, tc.Footer)
}
})
}
}