Address code review changes.
Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>pull/597/head
parent
31d8c300d7
commit
465976789b
|
|
@ -363,7 +363,11 @@ $ GO111MODULE=on go get github.com/golang/mock/mockgen@v1.4.4
|
|||
Generate new mock for go interface. Example:
|
||||
|
||||
```bash
|
||||
$ mockgen -source=pkg/util/process.go -destination=mocks/process_mock.go
|
||||
$ mockgen -source=pkg/util/process.go -destination=mocks/pkg/util/process_mock.go -package mock_util
|
||||
|
||||
$ mockgen -source=pkg/controller/che/oauth_initial_htpasswd_provider.go \
|
||||
-destination=mocks/pkg/controller/che/oauth_initial_htpasswd_provider_mock.go \
|
||||
-package mock_che
|
||||
```
|
||||
|
||||
See more: https://github.com/golang/mock/blob/master/README.md
|
||||
See more: https://github.com/golang/mock/blob/master/README.md
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: pkg/controller/che/initial-htpasswd-provider.go
|
||||
|
||||
// Package mock_che is a generated GoMock package.
|
||||
package mock_util
|
||||
|
||||
import (
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
v1 "github.com/openshift/api/config/v1"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockInitialUserHandler is a mock of InitialUserHandler interface
|
||||
type MockInitialUserHandler struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockInitialUserHandlerMockRecorder
|
||||
}
|
||||
|
||||
// MockInitialUserHandlerMockRecorder is the mock recorder for MockInitialUserHandler
|
||||
type MockInitialUserHandlerMockRecorder struct {
|
||||
mock *MockInitialUserHandler
|
||||
}
|
||||
|
||||
// NewMockInitialUserHandler creates a new mock instance
|
||||
func NewMockInitialUserHandler(ctrl *gomock.Controller) *MockInitialUserHandler {
|
||||
mock := &MockInitialUserHandler{ctrl: ctrl}
|
||||
mock.recorder = &MockInitialUserHandlerMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (m *MockInitialUserHandler) EXPECT() *MockInitialUserHandlerMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// CreateOauthInitialUser mocks base method
|
||||
func (m *MockInitialUserHandler) CreateOauthInitialUser(crNamespace string, openshiftOAuth *v1.OAuth) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CreateOauthInitialUser", crNamespace, openshiftOAuth)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// CreateOauthInitialUser indicates an expected call of CreateOauthInitialUser
|
||||
func (mr *MockInitialUserHandlerMockRecorder) CreateOauthInitialUser(crNamespace, openshiftOAuth interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOauthInitialUser", reflect.TypeOf((*MockInitialUserHandler)(nil).CreateOauthInitialUser), crNamespace, openshiftOAuth)
|
||||
}
|
||||
|
||||
// DeleteOauthInitialUser mocks base method
|
||||
func (m *MockInitialUserHandler) DeleteOauthInitialUser(crNamespace string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DeleteOauthInitialUser", crNamespace)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DeleteOauthInitialUser indicates an expected call of DeleteOauthInitialUser
|
||||
func (mr *MockInitialUserHandlerMockRecorder) DeleteOauthInitialUser(crNamespace interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOauthInitialUser", reflect.TypeOf((*MockInitialUserHandler)(nil).DeleteOauthInitialUser), crNamespace)
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: pkg/controller/che/oauth_initial_htpasswd_provider.go
|
||||
|
||||
// Package mock_che is a generated GoMock package.
|
||||
package mock_che
|
||||
|
||||
import (
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
v1 "github.com/openshift/api/config/v1"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockOpenShiftOAuthUserHandler is a mock of OpenShiftOAuthUserHandler interface
|
||||
type MockOpenShiftOAuthUserHandler struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockOpenShiftOAuthUserHandlerMockRecorder
|
||||
}
|
||||
|
||||
// MockOpenShiftOAuthUserHandlerMockRecorder is the mock recorder for MockOpenShiftOAuthUserHandler
|
||||
type MockOpenShiftOAuthUserHandlerMockRecorder struct {
|
||||
mock *MockOpenShiftOAuthUserHandler
|
||||
}
|
||||
|
||||
// NewMockOpenShiftOAuthUserHandler creates a new mock instance
|
||||
func NewMockOpenShiftOAuthUserHandler(ctrl *gomock.Controller) *MockOpenShiftOAuthUserHandler {
|
||||
mock := &MockOpenShiftOAuthUserHandler{ctrl: ctrl}
|
||||
mock.recorder = &MockOpenShiftOAuthUserHandlerMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (m *MockOpenShiftOAuthUserHandler) EXPECT() *MockOpenShiftOAuthUserHandlerMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// CreateOAuthInitialUser mocks base method
|
||||
func (m *MockOpenShiftOAuthUserHandler) CreateOAuthInitialUser(crNamespace string, openshiftOAuth *v1.OAuth) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CreateOAuthInitialUser", crNamespace, openshiftOAuth)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// CreateOAuthInitialUser indicates an expected call of CreateOAuthInitialUser
|
||||
func (mr *MockOpenShiftOAuthUserHandlerMockRecorder) CreateOAuthInitialUser(crNamespace, openshiftOAuth interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOAuthInitialUser", reflect.TypeOf((*MockOpenShiftOAuthUserHandler)(nil).CreateOAuthInitialUser), crNamespace, openshiftOAuth)
|
||||
}
|
||||
|
||||
// DeleteOAuthInitialUser mocks base method
|
||||
func (m *MockOpenShiftOAuthUserHandler) DeleteOAuthInitialUser(crNamespace string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DeleteOAuthInitialUser", crNamespace)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DeleteOAuthInitialUser indicates an expected call of DeleteOAuthInitialUser
|
||||
func (mr *MockOpenShiftOAuthUserHandlerMockRecorder) DeleteOAuthInitialUser(crNamespace interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOAuthInitialUser", reflect.TypeOf((*MockOpenShiftOAuthUserHandler)(nil).DeleteOAuthInitialUser), crNamespace)
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ func newReconciler(mgr manager.Manager) (reconcile.Reconciler, error) {
|
|||
nonCachedClient: noncachedClient,
|
||||
scheme: mgr.GetScheme(),
|
||||
discoveryClient: discoveryClient,
|
||||
userHandler: NewInitialUserHandler(noncachedClient),
|
||||
userHandler: NewOpenShiftOAuthUserHandler(noncachedClient),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -278,7 +278,7 @@ type ReconcileChe struct {
|
|||
discoveryClient discovery.DiscoveryInterface
|
||||
scheme *runtime.Scheme
|
||||
tests bool
|
||||
userHandler InitialUserHandler
|
||||
userHandler OpenShiftOAuthUserHandler
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
@ -372,21 +372,19 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
|
|||
}
|
||||
}
|
||||
|
||||
if isOpenShift4 && !instance.Spec.Auth.CreateInitialUser {
|
||||
if err := r.userHandler.DeleteOauthInitialUser(instance.Namespace); err != nil {
|
||||
if isOpenShift4 && !instance.Spec.Auth.CreateOpenShiftOAuthUser && instance.Status.OpenShiftOAuthUserCredentialsSecret != "" {
|
||||
if err := r.userHandler.DeleteOAuthInitialUser(instance.Namespace); err != nil {
|
||||
logrus.Errorf("Unable to delete initial user from cluster. Cause: %s", err.Error())
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
if instance.Status.IdentityProviderInitialUserSecret != "" {
|
||||
instance.Status.IdentityProviderInitialUserSecret = ""
|
||||
if err := r.UpdateCheCRStatus(instance, "IdentityProviderInitialUserSecret", initialUserSecret); err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
instance.Status.OpenShiftOAuthUserCredentialsSecret = ""
|
||||
if err := r.UpdateCheCRStatus(instance, "IdentityProviderInitialUserSecret", openShiftOAuthUserCredentialsSecret); err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
}
|
||||
|
||||
if isOpenShift && instance.Spec.Auth.OpenShiftoAuth == nil ||
|
||||
(util.IsOAuthEnabled(instance) && instance.Spec.Auth.CreateInitialUser) {
|
||||
(util.IsOAuthEnabled(instance) && instance.Spec.Auth.CreateOpenShiftOAuthUser) {
|
||||
if reconcileResult, err := r.autoEnableOAuth(deployContext, request, isOpenShift4); err != nil {
|
||||
return reconcileResult, err
|
||||
}
|
||||
|
|
@ -1136,17 +1134,17 @@ func (r *ReconcileChe) autoEnableOAuth(deployContext *deploy.DeployContext, requ
|
|||
} else {
|
||||
if len(openshitOAuth.Spec.IdentityProviders) > 0 {
|
||||
oauth = true
|
||||
} else if cr.Spec.Auth.CreateInitialUser {
|
||||
if err := r.userHandler.CreateOauthInitialUser(deployContext.CheCluster.Namespace, openshitOAuth); err != nil {
|
||||
} else if cr.Spec.Auth.CreateOpenShiftOAuthUser {
|
||||
if err := r.userHandler.CreateOAuthInitialUser(deployContext.CheCluster.Namespace, openshitOAuth); err != nil {
|
||||
message = warningNoIdentityProvidersMessage + " Operator tried to create initial identity provider, but failed. Cause: " + err.Error()
|
||||
logrus.Warn(message)
|
||||
logrus.Info(" You can create identity provider manually:" + howToAddIdentityProviderLinkOS4)
|
||||
reason = failedNoIdentityProviders
|
||||
} else {
|
||||
oauth = true
|
||||
if deployContext.CheCluster.Status.IdentityProviderInitialUserSecret == "" {
|
||||
deployContext.CheCluster.Status.IdentityProviderInitialUserSecret = initialUserSecret
|
||||
if err := r.UpdateCheCRStatus(cr, "IdentityProviderInitialUserSecret", initialUserSecret); err != nil {
|
||||
if deployContext.CheCluster.Status.OpenShiftOAuthUserCredentialsSecret == "" {
|
||||
deployContext.CheCluster.Status.OpenShiftOAuthUserCredentialsSecret = openShiftOAuthUserCredentialsSecret
|
||||
if err := r.UpdateCheCRStatus(cr, "openShiftOAuthUserCredentialsSecret", openShiftOAuthUserCredentialsSecret); err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ import (
|
|||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
mocks "github.com/eclipse/che-operator/mocks"
|
||||
che_mocks "github.com/eclipse/che-operator/mocks/pkg/controller/che"
|
||||
|
||||
rbacapi "k8s.io/api/rbac/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
|
|
@ -202,14 +202,14 @@ func init() {
|
|||
|
||||
func TestCaseAutoDetectOAuth(t *testing.T) {
|
||||
type testCase struct {
|
||||
name string
|
||||
initObjects []runtime.Object
|
||||
openshiftVersion string
|
||||
initialOAuthValue *bool
|
||||
oAuthExpected *bool
|
||||
createInitialUser bool
|
||||
IdentityProviderInitialUserSecret string
|
||||
mockFunction func(ctrl *gomock.Controller, crNamespace string) *mocks.MockInitialUserHandler
|
||||
name string
|
||||
initObjects []runtime.Object
|
||||
openshiftVersion string
|
||||
initialOAuthValue *bool
|
||||
oAuthExpected *bool
|
||||
createOpenshiftOAuthUser bool
|
||||
OpenShiftOAuthUserCredentialsSecret string
|
||||
mockFunction func(ctrl *gomock.Controller, crNamespace string) *che_mocks.MockOpenShiftOAuthUserHandler
|
||||
}
|
||||
|
||||
testCases := []testCase{
|
||||
|
|
@ -281,49 +281,39 @@ func TestCaseAutoDetectOAuth(t *testing.T) {
|
|||
openshiftVersion: "4",
|
||||
initialOAuthValue: nil,
|
||||
oAuthExpected: util.NewBoolPointer(true),
|
||||
mockFunction: func(ctrl *gomock.Controller, crNamespace string) *mocks.MockInitialUserHandler {
|
||||
m := mocks.NewMockInitialUserHandler(ctrl)
|
||||
m.EXPECT().DeleteOauthInitialUser(crNamespace)
|
||||
return m
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "che-operator should respect oAuth = true even if there no indentity providers on the Openshift 4",
|
||||
initObjects: []runtime.Object{
|
||||
oAuthWithNoIdentityProviders,
|
||||
},
|
||||
openshiftVersion: "4",
|
||||
initialOAuthValue: util.NewBoolPointer(true),
|
||||
oAuthExpected: util.NewBoolPointer(true),
|
||||
createInitialUser: true,
|
||||
mockFunction: func(ctrl *gomock.Controller, crNamespace string) *mocks.MockInitialUserHandler {
|
||||
m := mocks.NewMockInitialUserHandler(ctrl)
|
||||
m.EXPECT().CreateOauthInitialUser(crNamespace, gomock.Any())
|
||||
openshiftVersion: "4",
|
||||
initialOAuthValue: util.NewBoolPointer(true),
|
||||
oAuthExpected: util.NewBoolPointer(true),
|
||||
createOpenshiftOAuthUser: true,
|
||||
mockFunction: func(ctrl *gomock.Controller, crNamespace string) *che_mocks.MockOpenShiftOAuthUserHandler {
|
||||
m := che_mocks.NewMockOpenShiftOAuthUserHandler(ctrl)
|
||||
m.EXPECT().CreateOAuthInitialUser(crNamespace, gomock.Any())
|
||||
return m
|
||||
},
|
||||
IdentityProviderInitialUserSecret: "initial-user-secret",
|
||||
OpenShiftOAuthUserCredentialsSecret: "openshift-oauth-user-credentials",
|
||||
},
|
||||
{
|
||||
name: "che-operator should respect oAuth = true even if there are some users on the Openshift 4",
|
||||
initObjects: []runtime.Object{
|
||||
oAuthWithIdentityProvider,
|
||||
},
|
||||
openshiftVersion: "4",
|
||||
initialOAuthValue: util.NewBoolPointer(true),
|
||||
oAuthExpected: util.NewBoolPointer(true),
|
||||
createInitialUser: true,
|
||||
openshiftVersion: "4",
|
||||
initialOAuthValue: util.NewBoolPointer(true),
|
||||
oAuthExpected: util.NewBoolPointer(true),
|
||||
createOpenshiftOAuthUser: true,
|
||||
},
|
||||
{
|
||||
name: "che-operator should respect oAuth = false even if there no indentity providers on the Openshift 4",
|
||||
initObjects: []runtime.Object{
|
||||
oAuthWithNoIdentityProviders,
|
||||
},
|
||||
openshiftVersion: "4",
|
||||
mockFunction: func(ctrl *gomock.Controller, crNamespace string) *mocks.MockInitialUserHandler {
|
||||
m := mocks.NewMockInitialUserHandler(ctrl)
|
||||
m.EXPECT().DeleteOauthInitialUser(crNamespace)
|
||||
return m
|
||||
},
|
||||
openshiftVersion: "4",
|
||||
initialOAuthValue: util.NewBoolPointer(false),
|
||||
oAuthExpected: util.NewBoolPointer(false),
|
||||
},
|
||||
|
|
@ -332,25 +322,17 @@ func TestCaseAutoDetectOAuth(t *testing.T) {
|
|||
initObjects: []runtime.Object{
|
||||
oAuthWithIdentityProvider,
|
||||
},
|
||||
openshiftVersion: "4",
|
||||
mockFunction: func(ctrl *gomock.Controller, crNamespace string) *mocks.MockInitialUserHandler {
|
||||
m := mocks.NewMockInitialUserHandler(ctrl)
|
||||
m.EXPECT().DeleteOauthInitialUser(crNamespace)
|
||||
return m
|
||||
},
|
||||
openshiftVersion: "4",
|
||||
initialOAuthValue: util.NewBoolPointer(false),
|
||||
oAuthExpected: util.NewBoolPointer(false),
|
||||
},
|
||||
{
|
||||
name: "che-operator should auto disable oAuth on error retieve identity providers",
|
||||
initObjects: []runtime.Object{},
|
||||
openshiftVersion: "4",
|
||||
mockFunction: func(ctrl *gomock.Controller, crNamespace string) *mocks.MockInitialUserHandler {
|
||||
return mocks.NewMockInitialUserHandler(ctrl)
|
||||
},
|
||||
initialOAuthValue: nil,
|
||||
createInitialUser: true,
|
||||
oAuthExpected: util.NewBoolPointer(false),
|
||||
name: "che-operator should auto disable oAuth on error retieve identity providers",
|
||||
initObjects: []runtime.Object{},
|
||||
openshiftVersion: "4",
|
||||
initialOAuthValue: nil,
|
||||
createOpenshiftOAuthUser: true,
|
||||
oAuthExpected: util.NewBoolPointer(false),
|
||||
},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
|
|
@ -367,7 +349,7 @@ func TestCaseAutoDetectOAuth(t *testing.T) {
|
|||
initCR := InitCheWithSimpleCR().DeepCopy()
|
||||
initCR.Spec.Auth.OpenShiftoAuth = testCase.initialOAuthValue
|
||||
testCase.initObjects = append(testCase.initObjects, initCR)
|
||||
initCR.Spec.Auth.CreateInitialUser = testCase.createInitialUser
|
||||
initCR.Spec.Auth.CreateOpenShiftOAuthUser = testCase.createOpenshiftOAuthUser
|
||||
|
||||
cli := fake.NewFakeClientWithScheme(scheme, testCase.initObjects...)
|
||||
nonCachedClient := fake.NewFakeClientWithScheme(scheme, testCase.initObjects...)
|
||||
|
|
@ -380,7 +362,7 @@ func TestCaseAutoDetectOAuth(t *testing.T) {
|
|||
}
|
||||
|
||||
// prepare mocks
|
||||
var userHandlerMock *mocks.MockInitialUserHandler
|
||||
var userHandlerMock *che_mocks.MockOpenShiftOAuthUserHandler
|
||||
if testCase.mockFunction != nil {
|
||||
ctrl := gomock.NewController(t)
|
||||
userHandlerMock = testCase.mockFunction(ctrl, initCR.Namespace)
|
||||
|
|
@ -422,8 +404,8 @@ func TestCaseAutoDetectOAuth(t *testing.T) {
|
|||
t.Errorf("Openshift oAuth should be %t", *testCase.oAuthExpected)
|
||||
}
|
||||
|
||||
if cheCR.Status.IdentityProviderInitialUserSecret != testCase.IdentityProviderInitialUserSecret {
|
||||
t.Errorf("Expected initial user secret %s in the CR status", testCase.IdentityProviderInitialUserSecret)
|
||||
if cheCR.Status.OpenShiftOAuthUserCredentialsSecret != testCase.OpenShiftOAuthUserCredentialsSecret {
|
||||
t.Errorf("Expected initial openshift oAuth user secret %s in the CR status", testCase.OpenShiftOAuthUserCredentialsSecret)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -614,18 +596,11 @@ func TestImagePullerConfiguration(t *testing.T) {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Create controller, but don't call Finish(), because for this test we wants to have only mock itself.
|
||||
// We don't want to check method calling.
|
||||
ctrl := gomock.NewController(t)
|
||||
m := mocks.NewMockInitialUserHandler(ctrl)
|
||||
m.EXPECT().DeleteOauthInitialUser(testCase.initCR.Namespace)
|
||||
|
||||
r := &ReconcileChe{
|
||||
client: cli,
|
||||
nonCachedClient: nonCachedClient,
|
||||
discoveryClient: fakeDiscovery,
|
||||
scheme: scheme.Scheme,
|
||||
userHandler: m,
|
||||
}
|
||||
req := reconcile.Request{
|
||||
NamespacedName: types.NamespacedName{
|
||||
|
|
|
|||
|
|
@ -30,26 +30,26 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
htpasswdIdentityProviderName = "htpasswd-eclipse"
|
||||
htpasswdSecretName = "htpasswd-eclipse"
|
||||
ocConfigNamespace = "openshift-config"
|
||||
initialUserName = "che-user"
|
||||
openShiftOAuthUserCrednetialsSecret = "openshift-oauth-user-credentials"
|
||||
htpasswdIdentityProviderName = "htpasswd-eclipse"
|
||||
htpasswdSecretName = "htpasswd-eclipse"
|
||||
ocConfigNamespace = "openshift-config"
|
||||
initialUserName = "che-user"
|
||||
openShiftOAuthUserCredentialsSecret = "openshift-oauth-user-credentials"
|
||||
)
|
||||
|
||||
type InitialUserHandler interface {
|
||||
CreateOauthInitialUser(crNamespace string, openshiftOAuth *oauthv1.OAuth) error
|
||||
DeleteOauthInitialUser(crNamespace string) error
|
||||
type OpenShiftOAuthUserHandler interface {
|
||||
CreateOAuthInitialUser(crNamespace string, openshiftOAuth *oauthv1.OAuth) error
|
||||
DeleteOAuthInitialUser(crNamespace string) error
|
||||
}
|
||||
|
||||
type InitialUserOperatorHandler struct {
|
||||
InitialUserHandler
|
||||
type OpenShiftOAuthUserOperatorHandler struct {
|
||||
OpenShiftOAuthUserHandler
|
||||
runtimeClient client.Client
|
||||
runnable util.Runnable
|
||||
}
|
||||
|
||||
func NewInitialUserHandler(runtimeClient client.Client) InitialUserHandler {
|
||||
return &InitialUserOperatorHandler{
|
||||
func NewOpenShiftOAuthUserHandler(runtimeClient client.Client) OpenShiftOAuthUserHandler {
|
||||
return &OpenShiftOAuthUserOperatorHandler{
|
||||
runtimeClient: runtimeClient,
|
||||
// real process implementation. In the test we are using mock
|
||||
runnable: util.NewRunnable(),
|
||||
|
|
@ -61,7 +61,7 @@ func NewInitialUserHandler(runtimeClient client.Client) InitialUserHandler {
|
|||
// It usefull for good first user expirience.
|
||||
// User can't use kube:admin or system:admin user in the Openshift oAuth. That's why we provide
|
||||
// initial user for good first meeting with Eclipse Che.
|
||||
func (handler *InitialUserOperatorHandler) CreateOauthInitialUser(crNamespace string, openshiftOAuth *oauthv1.OAuth) error {
|
||||
func (handler *OpenShiftOAuthUserOperatorHandler) CreateOauthInitialUser(crNamespace string, openshiftOAuth *oauthv1.OAuth) error {
|
||||
password := util.GeneratePasswd(6)
|
||||
|
||||
htpasswdFileContent, err := handler.generateHtPasswdUserInfo(initialUserName, password)
|
||||
|
|
@ -87,7 +87,7 @@ func (handler *InitialUserOperatorHandler) CreateOauthInitialUser(crNamespace st
|
|||
}
|
||||
|
||||
initialUserSecretData := map[string][]byte{"user": []byte(initialUserName), "password": []byte(password)}
|
||||
if err := createSecret(initialUserSecretData, initialUserSecret, crNamespace, handler.runtimeClient); err != nil {
|
||||
if err := createSecret(initialUserSecretData, openShiftOAuthUserCredentialsSecret, crNamespace, handler.runtimeClient); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ func (handler *InitialUserOperatorHandler) CreateOauthInitialUser(crNamespace st
|
|||
}
|
||||
|
||||
// DeleteOauthInitialUser removes initial user, htpasswd provider, htpasswd secret and Che secret with username and password.
|
||||
func (iuh *InitialUserOperatorHandler) DeleteOauthInitialUser(crNamespace string) error {
|
||||
func (iuh *OpenShiftOAuthUserOperatorHandler) DeleteOauthInitialUser(crNamespace string) error {
|
||||
oAuth, err := GetOpenshiftOAuth(iuh.runtimeClient)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -113,7 +113,7 @@ func (iuh *InitialUserOperatorHandler) DeleteOauthInitialUser(crNamespace string
|
|||
return err
|
||||
}
|
||||
|
||||
if err := deleteSecret(initialUserSecret, crNamespace, iuh.runtimeClient); err != nil {
|
||||
if err := deleteSecret(openShiftOAuthUserCredentialsSecret, crNamespace, iuh.runtimeClient); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ func (iuh *InitialUserOperatorHandler) DeleteOauthInitialUser(crNamespace string
|
|||
return nil
|
||||
}
|
||||
|
||||
func (iuh *InitialUserOperatorHandler) generateHtPasswdUserInfo(username string, password string) (string, error) {
|
||||
func (iuh *OpenShiftOAuthUserOperatorHandler) generateHtPasswdUserInfo(username string, password string) (string, error) {
|
||||
logrus.Info("Generate initial user httpasswd info")
|
||||
|
||||
err := iuh.runnable.Run("htpasswd", "-nbB", username, password)
|
||||
|
|
@ -14,7 +14,7 @@ package che
|
|||
|
||||
import (
|
||||
"context"
|
||||
mocks "github.com/eclipse/che-operator/mocks"
|
||||
util_mocks "github.com/eclipse/che-operator/mocks/pkg/util"
|
||||
orgv1 "github.com/eclipse/che-operator/pkg/apis/org/v1"
|
||||
"github.com/golang/mock/gomock"
|
||||
oauth_config "github.com/openshift/api/config/v1"
|
||||
|
|
@ -61,13 +61,13 @@ func TestCreateInitialUser(t *testing.T) {
|
|||
runtimeClient := fake.NewFakeClientWithScheme(scheme, oAuth)
|
||||
|
||||
ctrl := gomock.NewController(t)
|
||||
m := mocks.NewMockRunnable(ctrl)
|
||||
m := util_mocks.NewMockRunnable(ctrl)
|
||||
m.EXPECT().Run("htpasswd", "-nbB", gomock.Any(), gomock.Any()).Return(nil)
|
||||
m.EXPECT().GetStdOut().Return("test-string")
|
||||
m.EXPECT().GetStdErr().Return("")
|
||||
defer ctrl.Finish()
|
||||
|
||||
initialUserHandler := &InitialUserOperatorHandler{
|
||||
initialUserHandler := &OpenShiftOAuthUserOperatorHandler{
|
||||
runtimeClient: runtimeClient,
|
||||
runnable: m,
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ func TestCreateInitialUser(t *testing.T) {
|
|||
|
||||
// Check created objects
|
||||
expectedCheSecret := &corev1.Secret{}
|
||||
if err := runtimeClient.Get(context.TODO(), types.NamespacedName{Name: initialUserSecret, Namespace: testNamespace}, expectedCheSecret); err != nil {
|
||||
if err := runtimeClient.Get(context.TODO(), types.NamespacedName{Name: openShiftOAuthUserCredentialsSecret, Namespace: testNamespace}, expectedCheSecret); err != nil {
|
||||
t.Errorf("Initial user secret should exists")
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ func TestDeleteInitialUser(t *testing.T) {
|
|||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: initialUserSecret,
|
||||
Name: openShiftOAuthUserCredentialsSecret,
|
||||
Namespace: testNamespace,
|
||||
},
|
||||
}
|
||||
|
|
@ -147,7 +147,7 @@ func TestDeleteInitialUser(t *testing.T) {
|
|||
|
||||
runtimeClient := fake.NewFakeClientWithScheme(scheme, oAuth, cheSecret, htpasswdSecret, userIdentity, user)
|
||||
|
||||
initialUserHandler := &InitialUserOperatorHandler{
|
||||
initialUserHandler := &OpenShiftOAuthUserOperatorHandler{
|
||||
runtimeClient: runtimeClient,
|
||||
}
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ func TestDeleteInitialUser(t *testing.T) {
|
|||
}
|
||||
|
||||
expectedCheSecret := &corev1.Secret{}
|
||||
if err := runtimeClient.Get(context.TODO(), types.NamespacedName{Name: initialUserSecret, Namespace: testNamespace}, expectedCheSecret); !errors.IsNotFound(err) {
|
||||
if err := runtimeClient.Get(context.TODO(), types.NamespacedName{Name: openShiftOAuthUserCredentialsSecret, Namespace: testNamespace}, expectedCheSecret); !errors.IsNotFound(err) {
|
||||
t.Errorf("Initial user secret be deleted")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue