-
Notifications
You must be signed in to change notification settings - Fork 3
/
jwtutils_test.go
27 lines (22 loc) · 897 Bytes
/
jwtutils_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
package caddyshardrouter
import "testing"
var tokenStr = "eyJhbGciOiJSUzI1NiJ9.eyJjdXN0b21lciI6IndhbG1hcnQifQ.PZBoUWYkdcjnGO7mccnUYXuHTdrYGLSDR0GkbcwjtoNFG8OU4a-ALGTXgHrIijWerxb4f53Y4XqXtA0xWnkNiht6g1aUFzXwf2_kYPoEg2JRJUHJwR0pDsdSJHWi2pN9gnxTQETUNVOdokptTkCHOcHgJdA4g3Ywy83Sud9x5Apwbe0UZrU7yir7cIEu_HXHoeok2sxMSf1al0Kl6GwlamVB09edgkRFbx9953u-H6KHCC3u_Ku2zlif13JKiawnAqsO8RQtX1NzcWr2jdl0SQvLV0MuvIsQ-yr9w-t2tLKRbwhTYnbaARHHzK2GOtgg_ALcmz562N011P3YPtMqzg"
func TestParseJWT(t *testing.T) {
claims, err := ParseJWT(tokenStr)
if err != nil {
t.Error("got an error:", err)
}
customer, _ := claims["customer"].(string)
expected := "walmart"
if customer != expected {
t.Errorf("expected '%s' but got '%s'", expected, customer)
}
}
func BenchmarkParseJWT(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := ParseJWT(tokenStr)
if err != nil {
b.Error("got an error", err)
}
}
}