Add more tests (#1949)

* add more test code

* add more test code
This commit is contained in:
zryfish
2020-03-15 10:22:39 +08:00
committed by GitHub
parent f8e7d06b07
commit abf0d66b22
13 changed files with 444 additions and 55 deletions

View File

@@ -7,23 +7,30 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/cache"
)
type TokenAuthenticator struct {
// TokenAuthenticator implements kubernetes token authenticate interface with our custom logic.
// TokenAuthenticator will retrieve user info from cache by given token. If empty or invalid token
// was given, authenticator will still give passed response at the condition user will be user.Anonymous
// and group from user.AllUnauthenticated. This helps requests be passed along the handler chain,
// because some resources are public accessible.
type tokenAuthenticator struct {
cacheClient cache.Interface
}
func NewTokenAuthenticator(cacheClient cache.Interface) authenticator.Token {
return &TokenAuthenticator{
return &tokenAuthenticator{
cacheClient: cacheClient,
}
}
func (t *TokenAuthenticator) AuthenticateToken(ctx context.Context, token string) (*authenticator.Response, bool, error) {
func (t *tokenAuthenticator) AuthenticateToken(ctx context.Context, token string) (*authenticator.Response, bool, error) {
//if len(token) == 0 {
return &authenticator.Response{
User: &user.DefaultInfo{
Name: "admin",
Name: user.Anonymous,
UID: "",
Groups: nil,
Groups: []string{user.AllUnauthenticated},
Extra: nil,
},
}, true, nil
//}
}