fusenapi/utils/basic/request_parse_test.go
2023-08-28 18:38:34 +08:00

38 lines
1.5 KiB
Go

package basic
import (
"crypto/sha256"
"fusenapi/utils/auth"
"log"
"testing"
"time"
)
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 := "5JlPincPavgw0X/Fmj15xLId5vOEtdarc6hR1XlBx80="
log.Println(auth.GenerateJwtTokenUint64(auth.StringToHash(s), 999999999999999, time.Now().UTC().Unix(), 0, 0))
key := auth.StringToHash(s)
log.Println(key)
// log.Println(auth.GenerateJwtTokenUint64(auth.StringToHash(s), 400000000, time.Now().UTC().Unix(), 39, 0))
authkey := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjEwMDAwMDAwMDE2OTMyMTYxNDMsImd1ZXN0X2lkIjowLCJpYXQiOjE2OTMyMTYxNDQsInVzZXJfaWQiOjB9.KnesyIk9hNHlXPRkvqNmI7pf-icxmL8VB56zUm6ajxE"
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))
}