forked from o1egl/paseto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
43 lines (39 loc) · 1 KB
/
utils_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
package paseto
import (
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPreAuth(t *testing.T) {
cases := map[string]struct {
encoded string
pieces [][]byte
}{
"No data": {
encoded: "0000000000000000",
},
"One empty element": {
encoded: "01000000000000000000000000000000",
pieces: [][]byte{{}},
},
"Two empty elements": {
encoded: "020000000000000000000000000000000000000000000000",
pieces: [][]byte{{}, {}},
},
"One non empty element": {
encoded: "0100000000000000070000000000000050617261676f6e",
pieces: [][]byte{[]byte("Paragon")},
},
"Two non empty elements": {
encoded: "0200000000000000070000000000000050617261676f6e0a00000000000000496e6974696174697665",
pieces: [][]byte{[]byte("Paragon"), []byte("Initiative")},
},
}
for name, test := range cases {
t.Run(name, func(t *testing.T) {
if b, err := hex.DecodeString(test.encoded); assert.NoError(t, err) {
assert.Equal(t, b, preAuthEncode(test.pieces...))
}
})
}
}