fix e2e auth error

Signed-off-by: Roland.Ma <rolandma@kubesphere.io>
This commit is contained in:
Roland.Ma
2021-10-22 01:27:17 +00:00
parent 744233b3a3
commit 64a4b65d66
5 changed files with 29 additions and 23 deletions

View File

@@ -130,6 +130,7 @@ func (p *passwordAuthenticator) Authenticate(_ context.Context, username, passwo
} }
u := &authuser.DefaultInfo{ u := &authuser.DefaultInfo{
Name: user.Name, Name: user.Name,
Groups: user.Spec.Groups,
} }
// check if the password is initialized // check if the password is initialized
if uninitialized := user.Annotations[iamv1alpha2.UninitializedAnnotation]; uninitialized != "" { if uninitialized := user.Annotations[iamv1alpha2.UninitializedAnnotation]; uninitialized != "" {

View File

@@ -1091,6 +1091,7 @@ func (am *amOperator) ListGroupRoleBindings(workspace string, query *query.Query
result = append(result, roleBinding) result = append(result, roleBinding)
} }
} }
if am.devopsProjectLister != nil {
devOpsProjects, err := am.devopsProjectLister.List(labels.SelectorFromSet(labels.Set{tenantv1alpha1.WorkspaceLabel: workspace})) devOpsProjects, err := am.devopsProjectLister.List(labels.SelectorFromSet(labels.Set{tenantv1alpha1.WorkspaceLabel: workspace}))
if err != nil { if err != nil {
return nil, err return nil, err
@@ -1106,6 +1107,7 @@ func (am *amOperator) ListGroupRoleBindings(workspace string, query *query.Query
result = append(result, roleBinding) result = append(result, roleBinding)
} }
} }
}
return result, nil return result, nil
} }

View File

@@ -155,6 +155,9 @@ func (f *Framework) GenericClient(userAgent string) client.Client {
Host: ctx.Host, Host: ctx.Host,
Username: ctx.Username, Username: ctx.Username,
Password: ctx.Password, Password: ctx.Password,
ContentConfig: rest.ContentConfig{
ContentType: runtime.ContentTypeJSON,
},
} }
rest.AddUserAgent(config, userAgent) rest.AddUserAgent(config, userAgent)

View File

@@ -34,13 +34,10 @@ import (
func NewClient(s *runtime.Scheme, user, passsword string) (client.Client, error) { func NewClient(s *runtime.Scheme, user, passsword string) (client.Client, error) {
ctx := framework.TestContext ctx := framework.TestContext
token, err := getToken(ctx.Host, user, passsword)
if err != nil {
return nil, err
}
config := &rest.Config{ config := &rest.Config{
Host: ctx.Host, Host: ctx.Host,
BearerToken: token.AccessToken, Username: user,
Password: passsword,
} }
return generic.New(config, client.Options{Scheme: s}) return generic.New(config, client.Options{Scheme: s})
@@ -48,13 +45,10 @@ func NewClient(s *runtime.Scheme, user, passsword string) (client.Client, error)
func NewRestClient(user, passsword string) (*restclient.RestClient, error) { func NewRestClient(user, passsword string) (*restclient.RestClient, error) {
ctx := framework.TestContext ctx := framework.TestContext
token, err := getToken(ctx.Host, user, passsword)
if err != nil {
return nil, err
}
config := &rest.Config{ config := &rest.Config{
Host: ctx.Host, Host: ctx.Host,
BearerToken: token.AccessToken, Username: user,
Password: passsword,
} }
return restclient.NewForConfig(config) return restclient.NewForConfig(config)

View File

@@ -27,6 +27,7 @@ import (
"kubesphere.io/api/iam/v1alpha2" "kubesphere.io/api/iam/v1alpha2"
"kubesphere.io/kubesphere/pkg/utils/stringutils"
"kubesphere.io/kubesphere/test/e2e/constant" "kubesphere.io/kubesphere/test/e2e/constant"
"kubesphere.io/kubesphere/test/e2e/framework" "kubesphere.io/kubesphere/test/e2e/framework"
"kubesphere.io/kubesphere/test/e2e/framework/iam" "kubesphere.io/kubesphere/test/e2e/framework/iam"
@@ -73,6 +74,11 @@ var _ = Describe("Groups", func() {
_, err = restClient.IamV1alpha2().Groups().CreateBinding(context.TODO(), workspace, group, UserName) _, err = restClient.IamV1alpha2().Groups().CreateBinding(context.TODO(), workspace, group, UserName)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Eventually(func() bool {
user, err := iam.GetUser(adminClient, UserName)
return err == nil && stringutils.FindString(user.Spec.Groups, group) != -1
}, timeout, interval).Should(BeTrue())
By("Creating a new client with user authentication") By("Creating a new client with user authentication")
userClient, err = iam.NewClient(f.GetScheme(), u.Name, constant.DefaultPassword) userClient, err = iam.NewClient(f.GetScheme(), u.Name, constant.DefaultPassword)
framework.ExpectNoError(err) framework.ExpectNoError(err)