-
Notifications
You must be signed in to change notification settings - Fork 0
/
jwt_test.go
42 lines (36 loc) · 941 Bytes
/
jwt_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
package jwt
import (
"testing"
)
func TestJWT_Sign(t *testing.T) {
// preparing jwt
jwt, err := New()
if err != nil {
t.Fatalf("jwt setup error: %s", err.Error())
return
}
token, err := jwt.Sign(123456)
if err != nil {
t.Fatalf("sign error: %s", err.Error())
return
}
t.Logf("token: \n%s\n", token)
}
func TestJWT_Parse(t *testing.T) {
// preparing jwt
jwt, err := New()
if err != nil {
t.Fatalf("jwt setup error: %s", err.Error())
return
}
const token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxMjM0NTYsImlzcy" +
"I6IlRlbGVicm9hZCBMTEMiLCJzdWIiOiJTaXBweSBQcm94eSIsImV4cCI6MTY0ODI2NDAwMiwibmJ" +
"mIjoxNjQ4MDA0ODAyLCJpYXQiOjE2NDgwMDQ4MDIsImp0aSI6IjEyMzQ1NiJ9.BHvXxis1QptK2Hh" +
"LaGC0u9IUaS9UUiZ3kRs_ygiJgG9pZkhPJKJFG-XqT_WbA2P9Z-lDaG_p2RxSctocYdk3CQ"
claims, err := jwt.Parse(token)
if err != nil {
t.Fatalf("sign error: %s", err.Error())
return
}
t.Logf("claims: %#+v", claims)
}