package basic import ( "crypto/sha256" "encoding/base64" "fusenapi/utils/auth" "log" "testing" ) func TestRequestParse(t *testing.T) { a, us, err := auth.TParseJwtTokenHeader[auth.UserInfo]("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjQ3MjYwMzQsImd1ZXN0X2lkIjo2NywiaWF0IjozMTUzNjAwMCwidXNlcl9pZCI6MH0.VNsqg1479iNk_aiAz_8VNiiSL3kr047dNcpCvwM56Ck") log.Println(a, us, err) } func TestHash(t *testing.T) { a := "fs12345678" h := sha256.New() h.Write([]byte(a)) s := base64.RawURLEncoding.EncodeToString(h.Sum(nil)) key := auth.StringToHash(s) log.Println(key) // log.Println(auth.GenerateJwtTokenUint64(auth.StringToHash(s), 400000000, time.Now().UTC().Unix(), 39, 0)) authkey := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjIwOTMxOTIyMjYsImd1ZXN0X2lkIjowLCJpYXQiOjE2OTMxOTIyMjYsInVzZXJfaWQiOjM5fQ.DrvtD7gKB0gz1rAOAQHSnyBK3exTFqoLlacpZiadpB4" log.Println(authkey) log.Println(auth.TParseJwtTokenHeader[auth.UserInfo](authkey)) log.Println(auth.ParseJwtTokenUint64Secret(authkey, key)) } func TestGuestIdToken(t *testing.T) { a := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjQ3MzAzNDAsImd1ZXN0X2lkIjo3MywiaWF0IjozMTUzNjAwMCwidXNlcl9pZCI6MH0.XTMSjZpSwbBDxGsM2G4B386lV4IMrQDgobMsboCbWhI" auth.TParseJwtTokenHeader[auth.UserInfo](a) log.Println(auth.TParseJwtTokenHeader[auth.UserInfo](a)) log.Println(auth.ParseJwtTokenUint64Secret(a, auth.DefaultJwtSecret)) }