token cache config

Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
hongming
2020-04-13 14:24:01 +08:00
parent 17013d3519
commit 3ce4a0d77c
8 changed files with 326 additions and 15 deletions

View File

@@ -21,6 +21,7 @@ package token
import (
"github.com/google/go-cmp/cmp"
"k8s.io/apiserver/pkg/authentication/user"
"kubesphere.io/kubesphere/pkg/apiserver/authentication/oauth"
authoptions "kubesphere.io/kubesphere/pkg/apiserver/authentication/options"
"kubesphere.io/kubesphere/pkg/simple/client/cache"
"testing"
@@ -70,3 +71,39 @@ func TestJwtTokenIssuer(t *testing.T) {
})
}
}
func TestTokenVerifyWithoutCacheValidate(t *testing.T) {
options := authoptions.NewAuthenticateOptions()
// do not set token cache and disable token cache validate,
options.OAuthOptions = &oauth.Options{AccessTokenMaxAge: 0}
options.JwtSecret = "kubesphere"
issuer := NewJwtTokenIssuer(DefaultIssuerName, options, nil)
client, err := options.OAuthOptions.OAuthClient("default")
if err != nil {
t.Fatal(err)
}
user := &user.DefaultInfo{
Name: "admin",
UID: "admin",
}
tokenString, err := issuer.IssueTo(user, *client.AccessTokenMaxAge)
if err != nil {
t.Fatal(err)
}
got, err := issuer.Verify(tokenString)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(got, user); diff != "" {
t.Error("token validate failed")
}
}