fusenapi/utils/basic/request_parse_test.go

37 lines
1.4 KiB
Go
Raw Normal View History

2023-08-25 07:37:35 +00:00
package basic
import (
2023-08-28 03:28:09 +00:00
"crypto/sha256"
"encoding/base64"
2023-08-25 07:37:35 +00:00
"fusenapi/utils/auth"
"log"
"testing"
)
func TestRequestParse(t *testing.T) {
2023-08-28 04:11:57 +00:00
a, us, err := auth.TParseJwtTokenHeader[auth.UserInfo]("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjQ3MjYwMzQsImd1ZXN0X2lkIjo2NywiaWF0IjozMTUzNjAwMCwidXNlcl9pZCI6MH0.VNsqg1479iNk_aiAz_8VNiiSL3kr047dNcpCvwM56Ck")
2023-08-25 07:37:35 +00:00
log.Println(a, us, err)
}
2023-08-28 03:28:09 +00:00
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)
2023-08-28 04:11:57 +00:00
log.Println(key)
2023-08-28 03:28:09 +00:00
// 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))
}
2023-08-28 04:11:57 +00:00
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))
}