31 lines
540 B
Go
31 lines
540 B
Go
package auth
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestGenJwt 测试jwt序列化
|
|
func TestGenJwt(t *testing.T) {
|
|
now := time.Now().Unix()
|
|
secret := "fusen123"
|
|
a, err := GenerateJwtToken(&secret, 3600, now, 123, 1234)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
// log.Println(a)
|
|
|
|
claims, err := getJwtClaims(a, &secret)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
userinfo, err := GetUserInfoFormMapClaims(claims)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if userinfo.UserId != 123 || userinfo.GuestId != 1234 {
|
|
t.Error(userinfo)
|
|
}
|
|
// log.Println(claims)
|
|
}
|