fusenapi/utils/auth/user_test.go
2023-06-14 18:17:45 +08:00

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)
}