osg VerifyJWT 추가
This commit is contained in:
@ -1,7 +1,11 @@
|
||||
package opensearch
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
@ -31,3 +35,44 @@ func TestNewClient(t *testing.T) {
|
||||
// time.Sleep(time.Second)
|
||||
// }
|
||||
}
|
||||
|
||||
func TestClient_MakeJWT(t *testing.T) {
|
||||
sk := "UGdiOTdLVjFBTWtndTRNRiZmVjdwMDdCRW1lSSUxTnA="
|
||||
dst := make([]byte, len(sk)*2)
|
||||
dstlen, _ := base64.StdEncoding.Decode(dst, []byte(sk))
|
||||
signingKey := dst[:dstlen]
|
||||
uid := primitive.NewObjectID().Hex()
|
||||
|
||||
type args struct {
|
||||
subject string
|
||||
role string
|
||||
ttl time.Duration
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
c *Client
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
{
|
||||
c: &Client{
|
||||
signingKey: signingKey,
|
||||
},
|
||||
args: args{
|
||||
subject: uid,
|
||||
role: "ds_client",
|
||||
ttl: time.Minute,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := tt.c.MakeJWT(tt.args.subject, tt.args.role, tt.args.ttl)
|
||||
subj, role := tt.c.VerifyJWT(got)
|
||||
if subj != tt.args.subject || role != tt.args.role {
|
||||
t.Errorf("Client.MakeJWT() = %v, %v, want %v, %v", subj, role, tt.args.subject, tt.args.role)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user