fusenapi/utils/basic/request_parse_test.go

38 lines
1.5 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"
2023-08-25 07:37:35 +00:00
"fusenapi/utils/auth"
"log"
"testing"
2023-08-28 06:21:06 +00:00
"time"
2023-08-25 07:37:35 +00:00
)
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))
2023-08-28 06:21:06 +00:00
s := "5JlPincPavgw0X/Fmj15xLId5vOEtdarc6hR1XlBx80="
2023-08-28 10:38:34 +00:00
log.Println(auth.GenerateJwtTokenUint64(auth.StringToHash(s), 999999999999999, time.Now().UTC().Unix(), 0, 0))
2023-08-28 03:28:09 +00:00
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))
2023-08-28 10:38:34 +00:00
authkey := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjEwMDAwMDAwMDE2OTMyMTYxNDMsImd1ZXN0X2lkIjowLCJpYXQiOjE2OTMyMTYxNDQsInVzZXJfaWQiOjB9.KnesyIk9hNHlXPRkvqNmI7pf-icxmL8VB56zUm6ajxE"
2023-08-28 03:28:09 +00:00
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))
}