79 lines
1.7 KiB
Go
79 lines
1.7 KiB
Go
package opensearch
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"testing"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
func TestNewClient(t *testing.T) {
|
|
// var cfg Config
|
|
|
|
// cfg.Addresses = []string{"http://localhost:9200"}
|
|
// client, err := NewClient(cfg)
|
|
// if err != nil {
|
|
// t.Errorf("NewClient() error = %v", err)
|
|
// return
|
|
// }
|
|
|
|
// for i := 0; i < 10; i++ {
|
|
// MakeActorLog("LOGIN", "test_user", "stalkername").Write(&client, bson.M{
|
|
// "country": "kr",
|
|
// "ip": "127.0.0.1",
|
|
// })
|
|
// time.Sleep(time.Second)
|
|
// }
|
|
|
|
// for i := 0; i < 10; i++ {
|
|
// MakeActorLog("Match", "test_user", "stalkername").Write(&client, bson.M{
|
|
// "server": "kr001",
|
|
// "mode": "pvp",
|
|
// "address": "server address",
|
|
// })
|
|
// 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)
|
|
}
|
|
})
|
|
}
|
|
}
|