Skip to content

remove oauth server dependency from most integration tests #18067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions test/util/client.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package util

import (
"encoding/base64"
"fmt"
"math/rand"
"os"
"path"
"path/filepath"
"time"

"github.com/pborman/uuid"

kerrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
Expand All @@ -20,10 +23,10 @@ import (

configapi "github.com/openshift/origin/pkg/cmd/server/api"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/tokencmd"
oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth"
oauthclient "github.com/openshift/origin/pkg/oauth/generated/internalclientset"
"github.com/openshift/origin/pkg/serviceaccounts"
userapi "github.com/openshift/origin/pkg/user/apis/user"
userclient "github.com/openshift/origin/pkg/user/generated/internalclientset"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still dependent on internal apis and auth, i guess i'm not seeing how i copy this pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still dependent on internal apis and auth, i guess i'm not seeing how i copy this pattern.

Hrm. All our integration tests are still on internal. I don't think I've done anything special that's internal only. Can you copy it and change the package imports to the externals?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe. it's bitten me in other places but i can try it.

)

Expand Down Expand Up @@ -62,14 +65,52 @@ func GetClusterAdminClientConfigOrDie(adminKubeConfigFile string) *restclient.Co
return conf
}

func GetClientForUser(clientConfig *restclient.Config, username string) (kclientset.Interface, *restclient.Config, error) {
token, err := tokencmd.RequestToken(clientConfig, nil, username, "password")
func GetClientForUser(clusterAdminConfig *restclient.Config, username string) (kclientset.Interface, *restclient.Config, error) {
userClient, err := userclient.NewForConfig(clusterAdminConfig)
if err != nil {
return nil, nil, err
}

user, err := userClient.User().Users().Get(username, metav1.GetOptions{})
if err != nil {
user = &userapi.User{
ObjectMeta: metav1.ObjectMeta{Name: username},
}
user, err = userClient.User().Users().Create(user)
if err != nil {
return nil, nil, err
}
}

oauthClient, err := oauthclient.NewForConfig(clusterAdminConfig)
if err != nil {
return nil, nil, err
}

userClientConfig := restclient.AnonymousClientConfig(clientConfig)
userClientConfig.BearerToken = token
oauthClientObj := &oauthapi.OAuthClient{
ObjectMeta: metav1.ObjectMeta{Name: "test-integration-client"},
}
if _, err := oauthClient.Oauth().OAuthClients().Create(oauthClientObj); err != nil && !kerrs.IsAlreadyExists(err) {
return nil, nil, err
}

randomToken := uuid.NewRandom()
accesstoken := base64.RawURLEncoding.EncodeToString([]byte(randomToken))
for i := len(accesstoken); i < 32; i++ {
accesstoken = accesstoken + "A"
}
token := &oauthapi.OAuthAccessToken{
ObjectMeta: metav1.ObjectMeta{Name: accesstoken},
ClientName: oauthClientObj.Name,
UserName: username,
UserUID: string(user.UID),
}
if _, err := oauthClient.Oauth().OAuthAccessTokens().Create(token); err != nil {
return nil, nil, err
}

userClientConfig := restclient.AnonymousClientConfig(clusterAdminConfig)
userClientConfig.BearerToken = token.Name

kubeClientset, err := kclientset.NewForConfig(userClientConfig)
if err != nil {
Expand Down
142 changes: 0 additions & 142 deletions test/util/verify.go

This file was deleted.