You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
1.8 KiB
98 lines
1.8 KiB
2 months ago
|
package auth
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/go-kratos/kratos/v2/middleware"
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/davecgh/go-spew/spew"
|
||
|
)
|
||
|
|
||
|
func TestGenerateToken(t *testing.T) {
|
||
|
tk := GenerateToken("matchmaking-system", 11)
|
||
|
spew.Dump(tk)
|
||
|
}
|
||
|
|
||
|
func TestFromContext(t *testing.T) {
|
||
|
type args struct {
|
||
|
ctx context.Context
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
want *CurrentUser
|
||
|
}{
|
||
|
// TODO: Add test cases.
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := FromContext(tt.args.ctx); !reflect.DeepEqual(got, tt.want) {
|
||
|
t.Errorf("FromContext() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestGenerateToken1(t *testing.T) {
|
||
|
type args struct {
|
||
|
secret string
|
||
|
userid uint
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
want string
|
||
|
}{
|
||
|
// TODO: Add test cases.
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := GenerateToken(tt.args.secret, tt.args.userid); got != tt.want {
|
||
|
t.Errorf("GenerateToken() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestJWTAuth(t *testing.T) {
|
||
|
type args struct {
|
||
|
secret string
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
want middleware.Middleware
|
||
|
}{
|
||
|
// TODO: Add test cases.
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := JWTAuth(tt.args.secret); !reflect.DeepEqual(got, tt.want) {
|
||
|
t.Errorf("JWTAuth() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestWithContext(t *testing.T) {
|
||
|
type args struct {
|
||
|
ctx context.Context
|
||
|
user *CurrentUser
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
want context.Context
|
||
|
}{
|
||
|
// TODO: Add test cases.
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := WithContext(tt.args.ctx, tt.args.user); !reflect.DeepEqual(got, tt.want) {
|
||
|
t.Errorf("WithContext() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|