diff options
author | Dennis Tang <dtang@gitlab.com> | 2018-06-11 22:57:04 -0700 |
---|---|---|
committer | Dennis Tang <dtang@gitlab.com> | 2018-06-19 15:01:43 +0000 |
commit | ce0ce1cb196e924b13631565114352ed89eba5af (patch) | |
tree | 4a73c43d1951e6507326312f1c214bc52887035f | |
parent | cc0305565704e8f713cd615f5a6767498bd03706 (diff) | |
download | gitlab-ce-ce0ce1cb196e924b13631565114352ed89eba5af.tar.gz |
consolidate back into one controller
-rw-r--r-- | app/assets/javascripts/pages/projects/clusters/gcp/new/index.js | 5 | ||||
-rw-r--r-- | app/assets/javascripts/pages/projects/index.js | 6 | ||||
-rw-r--r-- | app/controllers/projects/clusters/gcp_controller.rb | 45 | ||||
-rw-r--r-- | app/controllers/projects/clusters/user_controller.rb | 41 | ||||
-rw-r--r-- | app/controllers/projects/clusters_controller.rb | 113 | ||||
-rw-r--r-- | app/helpers/clusters_helper.rb | 41 | ||||
-rw-r--r-- | app/views/projects/clusters/gcp/_form.html.haml | 4 | ||||
-rw-r--r-- | app/views/projects/clusters/new.html.haml | 10 | ||||
-rw-r--r-- | app/views/projects/clusters/user/_form.html.haml | 2 | ||||
-rw-r--r-- | config/routes/project.rb | 6 | ||||
-rw-r--r-- | spec/controllers/projects/clusters/gcp_controller_spec.rb | 95 | ||||
-rw-r--r-- | spec/controllers/projects/clusters/user_controller_spec.rb | 57 | ||||
-rw-r--r-- | spec/controllers/projects/clusters_controller_spec.rb | 148 | ||||
-rw-r--r-- | spec/features/projects/clusters/gcp_spec.rb | 4 |
14 files changed, 263 insertions, 314 deletions
diff --git a/app/assets/javascripts/pages/projects/clusters/gcp/new/index.js b/app/assets/javascripts/pages/projects/clusters/gcp/new/index.js new file mode 100644 index 00000000000..d4f34e32a48 --- /dev/null +++ b/app/assets/javascripts/pages/projects/clusters/gcp/new/index.js @@ -0,0 +1,5 @@ +import initGkeDropdowns from '~/projects/gke_cluster_dropdowns'; + +document.addEventListener('DOMContentLoaded', () => { + initGkeDropdowns(); +}); diff --git a/app/assets/javascripts/pages/projects/index.js b/app/assets/javascripts/pages/projects/index.js index 7bbba9acb38..ba8bc5bc5fa 100644 --- a/app/assets/javascripts/pages/projects/index.js +++ b/app/assets/javascripts/pages/projects/index.js @@ -5,11 +5,7 @@ import ShortcutsNavigation from '../../shortcuts_navigation'; document.addEventListener('DOMContentLoaded', () => { const page = document.body.dataset.page; - const newClusterViews = [ - 'projects:clusters:new', - 'projects:clusters:gcp:create', - 'projects:clusters:user:create', - ]; + const newClusterViews = ['projects:clusters:new', 'projects:clusters:create']; if (newClusterViews.indexOf(page) > -1) { gcpSignupOffer(); diff --git a/app/controllers/projects/clusters/gcp_controller.rb b/app/controllers/projects/clusters/gcp_controller.rb deleted file mode 100644 index 9741164377b..00000000000 --- a/app/controllers/projects/clusters/gcp_controller.rb +++ /dev/null @@ -1,45 +0,0 @@ -class Projects::Clusters::GcpController < Projects::ApplicationController - include ClustersHelper - before_action :authorize_read_cluster! - before_action :authorize_create_cluster!, only: [:create] - helper_method :gcp_authorize_url - helper_method :token_in_session - helper_method :valid_gcp_token - - def create - if valid_gcp_token - @cluster = ::Clusters::CreateService - .new(project, current_user, create_params) - .execute(token_in_session) - - if @cluster.persisted? - redirect_to project_cluster_path(project, @cluster) - else - @gcp_cluster = @cluster - user_cluster - - render 'projects/clusters/new', locals: { active_tab: 'gcp' } - end - else - redirect_to new_project_cluster_path(@project) - end - end - - private - - def create_params - params.require(:cluster).permit( - :enabled, - :name, - :environment_scope, - provider_gcp_attributes: [ - :gcp_project_id, - :zone, - :num_nodes, - :machine_type - ]).merge( - provider_type: :gcp, - platform_type: :kubernetes - ) - end -end diff --git a/app/controllers/projects/clusters/user_controller.rb b/app/controllers/projects/clusters/user_controller.rb deleted file mode 100644 index 40bc3dc6f08..00000000000 --- a/app/controllers/projects/clusters/user_controller.rb +++ /dev/null @@ -1,41 +0,0 @@ -class Projects::Clusters::UserController < Projects::ApplicationController - include ClustersHelper - before_action :authorize_read_cluster! - before_action :authorize_create_cluster!, only: [:create] - helper_method :gcp_authorize_url - helper_method :token_in_session - helper_method :valid_gcp_token - - def create - @cluster = ::Clusters::CreateService - .new(project, current_user, create_params) - .execute - - if @cluster.persisted? - redirect_to project_cluster_path(project, @cluster) - else - @user_cluster = @cluster - gcp_cluster - - render 'projects/clusters/new', locals: { active_tab: 'user' } - end - end - - private - - def create_params - params.require(:cluster).permit( - :enabled, - :name, - :environment_scope, - platform_kubernetes_attributes: [ - :namespace, - :api_url, - :token, - :ca_cert - ]).merge( - provider_type: :user, - platform_type: :kubernetes - ) - end -end diff --git a/app/controllers/projects/clusters_controller.rb b/app/controllers/projects/clusters_controller.rb index 38140fe9f27..62193257940 100644 --- a/app/controllers/projects/clusters_controller.rb +++ b/app/controllers/projects/clusters_controller.rb @@ -1,16 +1,15 @@ class Projects::ClustersController < Projects::ApplicationController - include ClustersHelper - before_action :cluster, except: [:index, :new] + before_action :cluster, except: [:index, :new, :create_gcp, :create_user] before_action :authorize_read_cluster! + before_action :generate_gcp_authorize_url, only: [:new] + before_action :validate_gcp_token, only: [:new] before_action :gcp_cluster, only: [:new] before_action :user_cluster, only: [:new] before_action :authorize_create_cluster!, only: [:new] before_action :authorize_update_cluster!, only: [:update] before_action :authorize_admin_cluster!, only: [:destroy] before_action :update_applications_status, only: [:status] - helper_method :gcp_authorize_url helper_method :token_in_session - helper_method :valid_gcp_token STATUS_POLLING_INTERVAL = 10_000 @@ -70,6 +69,38 @@ class Projects::ClustersController < Projects::ApplicationController end end + def create_gcp + @gcp_cluster = ::Clusters::CreateService + .new(project, current_user, create_gcp_cluster_params) + .execute(token_in_session) + + if @gcp_cluster.persisted? + redirect_to project_cluster_path(project, @gcp_cluster) + else + generate_gcp_authorize_url + validate_gcp_token + user_cluster + + render :new, locals: { active_tab: 'gcp' } + end + end + + def create_user + @user_cluster = ::Clusters::CreateService + .new(project, current_user, create_user_cluster_params) + .execute(token_in_session) + + if @user_cluster.persisted? + redirect_to project_cluster_path(project, @user_cluster) + else + generate_gcp_authorize_url + validate_gcp_token + gcp_cluster + + render :new, locals: { active_tab: 'user' } + end + end + private def cluster @@ -101,6 +132,80 @@ class Projects::ClustersController < Projects::ApplicationController end end + def create_gcp_cluster_params + params.require(:cluster).permit( + :enabled, + :name, + :environment_scope, + provider_gcp_attributes: [ + :gcp_project_id, + :zone, + :num_nodes, + :machine_type + ]).merge( + provider_type: :gcp, + platform_type: :kubernetes + ) + end + + def create_user_cluster_params + params.require(:cluster).permit( + :enabled, + :name, + :environment_scope, + platform_kubernetes_attributes: [ + :namespace, + :api_url, + :token, + :ca_cert + ]).merge( + provider_type: :user, + platform_type: :kubernetes + ) + end + + def generate_gcp_authorize_url + state = generate_session_key_redirect(new_project_cluster_path(@project).to_s) + + @authorize_url = GoogleApi::CloudPlatform::Client.new( + nil, callback_google_api_auth_url, + state: state).authorize_url + rescue GoogleApi::Auth::ConfigMissingError + # no-op + end + + def gcp_cluster + @gcp_cluster = ::Clusters::Cluster.new.tap do |cluster| + cluster.build_provider_gcp + end + end + + def user_cluster + @user_cluster = ::Clusters::Cluster.new.tap do |cluster| + cluster.build_platform_kubernetes + end + end + + def validate_gcp_token + @valid_gcp_token = GoogleApi::CloudPlatform::Client.new(token_in_session, nil) + .validate_token(expires_at_in_session) + end + + def token_in_session + session[GoogleApi::CloudPlatform::Client.session_key_for_token] + end + + def expires_at_in_session + @expires_at_in_session ||= + session[GoogleApi::CloudPlatform::Client.session_key_for_expires_at] + end + + def generate_session_key_redirect(uri) + GoogleApi::CloudPlatform::Client.new_session_key_for_redirect_uri do |key| + session[key] = uri + end + end + def authorize_update_cluster! access_denied! unless can?(current_user, :update_cluster, cluster) end diff --git a/app/helpers/clusters_helper.rb b/app/helpers/clusters_helper.rb index 0663ef187e8..c24d340d184 100644 --- a/app/helpers/clusters_helper.rb +++ b/app/helpers/clusters_helper.rb @@ -10,45 +10,4 @@ module ClustersHelper render 'projects/clusters/gcp_signup_offer_banner' end end - - def gcp_cluster - @gcp_cluster = ::Clusters::Cluster.new.tap do |cluster| - cluster.build_provider_gcp - end - end - - def user_cluster - @user_cluster = ::Clusters::Cluster.new.tap do |cluster| - cluster.build_platform_kubernetes - end - end - - def gcp_authorize_url - state = generate_session_key_redirect(new_project_cluster_path(@project).to_s) - - GoogleApi::CloudPlatform::Client.new( - nil, callback_google_api_auth_url, - state: state).authorize_url - rescue GoogleApi::Auth::ConfigMissingError - # no-op - end - - def generate_session_key_redirect(uri) - GoogleApi::CloudPlatform::Client.new_session_key_for_redirect_uri do |key| - session[key] = uri - end - end - - def token_in_session - session[GoogleApi::CloudPlatform::Client.session_key_for_token] - end - - def expires_at_in_session - session[GoogleApi::CloudPlatform::Client.session_key_for_expires_at] - end - - def valid_gcp_token - GoogleApi::CloudPlatform::Client.new(token_in_session, nil) - .validate_token(expires_at_in_session) - end end diff --git a/app/views/projects/clusters/gcp/_form.html.haml b/app/views/projects/clusters/gcp/_form.html.haml index a6589cca529..1494998f95f 100644 --- a/app/views/projects/clusters/gcp/_form.html.haml +++ b/app/views/projects/clusters/gcp/_form.html.haml @@ -4,9 +4,9 @@ - link_to_help_page = link_to(s_('ClusterIntegration|help page'), help_page_path('user/project/clusters/index'), target: '_blank', rel: 'noopener noreferrer') = s_('ClusterIntegration|Read our %{link_to_help_page} on Kubernetes cluster integration.').html_safe % { link_to_help_page: link_to_help_page} -%p= link_to('Select a different Google account', gcp_authorize_url) +%p= link_to('Select a different Google account', @authorize_url) -= form_for @gcp_cluster, html: { class: 'js-gke-cluster-creation prepend-top-20', data: { token: token_in_session } }, url: gcp_namespace_project_clusters_path(@project.namespace, @project), as: :cluster do |field| += form_for @gcp_cluster, html: { class: 'js-gke-cluster-creation prepend-top-20', data: { token: token_in_session } }, url: create_gcp_namespace_project_clusters_path(@project.namespace, @project), as: :cluster do |field| = form_errors(@gcp_cluster) .form-group = field.label :name, s_('ClusterIntegration|Kubernetes cluster name') diff --git a/app/views/projects/clusters/new.html.haml b/app/views/projects/clusters/new.html.haml index 11b7c363553..d3b3bf2a2fe 100644 --- a/app/views/projects/clusters/new.html.haml +++ b/app/views/projects/clusters/new.html.haml @@ -7,7 +7,7 @@ .row.prepend-top-default .col-md-3 - = render 'projects/clusters/sidebar' + = render 'sidebar' .col-md-9.js-toggle-container %ul.nav-links.nav-tabs.gitlab-tabs.nav{ role: 'tablist' } %li.nav-item{ role: 'presentation' } @@ -15,16 +15,16 @@ %span Create new Cluster on GKE %li.nav-item{ role: 'presentation' } %a.nav-link{ href: '#add-user-cluster-pane', id: 'add-user-cluster-tab', class: active_when(active_tab == 'user'), data: { toggle: 'tab' }, role: 'tab' } - %span Add existing cluster + %span Add user cluster .tab-content.gitlab-tab-content .tab-pane{ id: 'create-gcp-cluster-pane', class: active_when(active_tab == 'gcp'), role: 'tabpanel' } = render 'projects/clusters/gcp/header' - - if valid_gcp_token + - if @valid_gcp_token = render 'projects/clusters/gcp/form' - - elsif gcp_authorize_url + - elsif @authorize_url .signin-with-google - = link_to(image_tag('auth_buttons/signin_with_google.png', width: '191px'), gcp_authorize_url) + = link_to(image_tag('auth_buttons/signin_with_google.png', width: '191px'), @authorize_url) = _('or') = link_to('create a new Google account', 'https://accounts.google.com/SignUpWithoutGmail?service=cloudconsole&continue=https%3A%2F%2Fconsole.cloud.google.com%2Ffreetrial%3Futm_campaign%3D2018_cpanel%26utm_source%3Dgitlab%26utm_medium%3Dreferral', target: '_blank', rel: 'noopener noreferrer') - else diff --git a/app/views/projects/clusters/user/_form.html.haml b/app/views/projects/clusters/user/_form.html.haml index 4167c8787ff..2f090e3fb86 100644 --- a/app/views/projects/clusters/user/_form.html.haml +++ b/app/views/projects/clusters/user/_form.html.haml @@ -1,4 +1,4 @@ -= form_for @user_cluster, url: user_namespace_project_clusters_path(@project.namespace, @project), as: :cluster do |field| += form_for @user_cluster, url: create_user_namespace_project_clusters_path(@project.namespace, @project), as: :cluster do |field| = form_errors(@user_cluster) .form-group = field.label :name, s_('ClusterIntegration|Kubernetes cluster name') diff --git a/config/routes/project.rb b/config/routes/project.rb index f672291a9f1..082a1166c41 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -206,10 +206,8 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do resources :clusters, except: [:edit, :create] do collection do - scope :providers do - post '/user', to: 'clusters/user#create' - post '/gcp', to: 'clusters/gcp#create' - end + post :create_gcp + post :create_user end member do diff --git a/spec/controllers/projects/clusters/gcp_controller_spec.rb b/spec/controllers/projects/clusters/gcp_controller_spec.rb deleted file mode 100644 index acaf2a1b948..00000000000 --- a/spec/controllers/projects/clusters/gcp_controller_spec.rb +++ /dev/null @@ -1,95 +0,0 @@ -require 'spec_helper' - -describe Projects::Clusters::GcpController do - include AccessMatchersForController - include GoogleApi::CloudPlatformHelpers - - set(:project) { create(:project) } - - describe 'POST create' do - let(:params) do - { - cluster: { - name: 'new-cluster', - provider_gcp_attributes: { - gcp_project_id: '111' - } - } - } - end - - before do - allow_any_instance_of(GoogleApi::CloudPlatform::Client) - .to receive(:projects_zones_clusters_create) do - OpenStruct.new( - self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123', - status: 'RUNNING' - ) - end - end - - describe 'functionality' do - let(:user) { create(:user) } - - before do - project.add_master(user) - sign_in(user) - end - - context 'when access token is valid' do - before do - stub_google_api_validate_token - end - - it 'creates a new cluster' do - expect(ClusterProvisionWorker).to receive(:perform_async) - expect { go }.to change { Clusters::Cluster.count } - .and change { Clusters::Providers::Gcp.count } - expect(response).to redirect_to(project_cluster_path(project, project.clusters.first)) - expect(project.clusters.first).to be_gcp - expect(project.clusters.first).to be_kubernetes - end - end - - context 'when access token is expired' do - before do - stub_google_api_expired_token - end - - it 'redirects to new clusters form' do - puts described_class - expect(go).to redirect_to(new_project_cluster_path(project)) - end - end - - context 'when access token is not stored in session' do - it 'redirects to new clusters form' do - expect(go).to redirect_to(new_project_cluster_path(project)) - end - end - end - - describe 'security' do - before do - allow_any_instance_of(described_class) - .to receive(:token_in_session).and_return('token') - allow_any_instance_of(described_class) - .to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s) - allow(WaitForClusterCreationWorker).to receive(:perform_in).and_return(nil) - end - - it { expect { go }.to be_allowed_for(:admin) } - it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } - it { expect { go }.to be_denied_for(:developer).of(project) } - it { expect { go }.to be_denied_for(:reporter).of(project) } - it { expect { go }.to be_denied_for(:guest).of(project) } - it { expect { go }.to be_denied_for(:user) } - it { expect { go }.to be_denied_for(:external) } - end - - def go - post :create, params.merge(namespace_id: project.namespace, project_id: project) - end - end -end diff --git a/spec/controllers/projects/clusters/user_controller_spec.rb b/spec/controllers/projects/clusters/user_controller_spec.rb deleted file mode 100644 index eba1c62a1f2..00000000000 --- a/spec/controllers/projects/clusters/user_controller_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'spec_helper' - -describe Projects::Clusters::UserController do - include AccessMatchersForController - - set(:project) { create(:project) } - - describe 'POST create' do - let(:params) do - { - cluster: { - name: 'new-cluster', - platform_kubernetes_attributes: { - api_url: 'http://my-url', - token: 'test', - namespace: 'aaa' - } - } - } - end - - describe 'functionality' do - let(:user) { create(:user) } - - before do - project.add_master(user) - sign_in(user) - end - - context 'when creates a cluster' do - it 'creates a new cluster' do - expect(ClusterProvisionWorker).to receive(:perform_async) - expect { go }.to change { Clusters::Cluster.count } - .and change { Clusters::Platforms::Kubernetes.count } - expect(response).to redirect_to(project_cluster_path(project, project.clusters.first)) - expect(project.clusters.first).to be_user - expect(project.clusters.first).to be_kubernetes - end - end - end - - describe 'security' do - it { expect { go }.to be_allowed_for(:admin) } - it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } - it { expect { go }.to be_denied_for(:developer).of(project) } - it { expect { go }.to be_denied_for(:reporter).of(project) } - it { expect { go }.to be_denied_for(:guest).of(project) } - it { expect { go }.to be_denied_for(:user) } - it { expect { go }.to be_denied_for(:external) } - end - - def go - post :create, params.merge(namespace_id: project.namespace, project_id: project) - end - end -end diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index a3aab70ab77..e47ccdc9aea 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -3,7 +3,6 @@ require 'spec_helper' describe Projects::ClustersController do include AccessMatchersForController include GoogleApi::CloudPlatformHelpers - include ClustersHelper set(:project) { create(:project) } @@ -76,13 +75,12 @@ describe Projects::ClustersController do end describe 'GET new' do - describe 'functionality for gcp cluster' do + describe 'functionality for new cluster' do let(:user) { create(:user) } before do project.add_master(user) sign_in(user) - @project = project end context 'when omniauth has been configured' do @@ -95,10 +93,10 @@ describe Projects::ClustersController do allow(SecureRandom).to receive(:hex).and_return(key) end - it 'has gcp_authorize_url' do + it 'has authorize_url' do go - expect(gcp_authorize_url).to include(key) + expect(assigns(:authorize_url)).to include(key) expect(session[session_key_for_redirect_uri]).to eq(new_project_cluster_path(project)) end end @@ -108,10 +106,10 @@ describe Projects::ClustersController do stub_omniauth_setting(providers: []) end - it 'does not have gcp_authorize_url' do + it 'does not have authorize_url' do go - expect(gcp_authorize_url).to be_nil + expect(assigns(:authorize_url)).to be_nil end end @@ -132,15 +130,15 @@ describe Projects::ClustersController do stub_google_api_expired_token end - it { expect(valid_gcp_token).to be_falsey } + it { expect(@valid_gcp_token).to be_falsey } end context 'when access token is not stored in session' do - it { expect(valid_gcp_token).to be_falsey } + it { expect(@valid_gcp_token).to be_falsey } end end - describe 'functionality for user cluster' do + describe 'functionality for existing cluster' do let(:user) { create(:user) } before do @@ -171,6 +169,136 @@ describe Projects::ClustersController do end end + describe 'POST create for new cluster' do + let(:params) do + { + cluster: { + name: 'new-cluster', + provider_gcp_attributes: { + gcp_project_id: 'gcp-project-12345' + } + } + } + end + + describe 'functionality' do + let(:user) { create(:user) } + + before do + project.add_master(user) + sign_in(user) + end + + context 'when access token is valid' do + before do + stub_google_api_validate_token + end + + it 'creates a new cluster' do + expect(ClusterProvisionWorker).to receive(:perform_async) + expect { go }.to change { Clusters::Cluster.count } + .and change { Clusters::Providers::Gcp.count } + expect(response).to redirect_to(project_cluster_path(project, project.clusters.first)) + expect(project.clusters.first).to be_gcp + expect(project.clusters.first).to be_kubernetes + end + end + + context 'when access token is expired' do + before do + stub_google_api_expired_token + end + + it { expect(@valid_gcp_token).to be_falsey } + end + + context 'when access token is not stored in session' do + it { expect(@valid_gcp_token).to be_falsey } + end + end + + describe 'security' do + before do + allow_any_instance_of(described_class) + .to receive(:token_in_session).and_return('token') + allow_any_instance_of(described_class) + .to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s) + allow_any_instance_of(GoogleApi::CloudPlatform::Client) + .to receive(:projects_zones_clusters_create) do + OpenStruct.new( + self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123', + status: 'RUNNING' + ) + end + + allow(WaitForClusterCreationWorker).to receive(:perform_in).and_return(nil) + end + + it { expect { go }.to be_allowed_for(:admin) } + it { expect { go }.to be_allowed_for(:owner).of(project) } + it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_denied_for(:developer).of(project) } + it { expect { go }.to be_denied_for(:reporter).of(project) } + it { expect { go }.to be_denied_for(:guest).of(project) } + it { expect { go }.to be_denied_for(:user) } + it { expect { go }.to be_denied_for(:external) } + end + + def go + post :create_gcp, params.merge(namespace_id: project.namespace, project_id: project) + end + end + + describe 'POST create for existing cluster' do + let(:params) do + { + cluster: { + name: 'new-cluster', + platform_kubernetes_attributes: { + api_url: 'http://my-url', + token: 'test', + namespace: 'aaa' + } + } + } + end + + describe 'functionality' do + let(:user) { create(:user) } + + before do + project.add_master(user) + sign_in(user) + end + + context 'when creates a cluster' do + it 'creates a new cluster' do + expect(ClusterProvisionWorker).to receive(:perform_async) + expect { go }.to change { Clusters::Cluster.count } + .and change { Clusters::Platforms::Kubernetes.count } + expect(response).to redirect_to(project_cluster_path(project, project.clusters.first)) + expect(project.clusters.first).to be_user + expect(project.clusters.first).to be_kubernetes + end + end + end + + describe 'security' do + it { expect { go }.to be_allowed_for(:admin) } + it { expect { go }.to be_allowed_for(:owner).of(project) } + it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_denied_for(:developer).of(project) } + it { expect { go }.to be_denied_for(:reporter).of(project) } + it { expect { go }.to be_denied_for(:guest).of(project) } + it { expect { go }.to be_denied_for(:user) } + it { expect { go }.to be_denied_for(:external) } + end + + def go + post :create_user, params.merge(namespace_id: project.namespace, project_id: project) + end + end + describe 'GET status' do let(:cluster) { create(:cluster, :providing_by_gcp, projects: [project]) } diff --git a/spec/features/projects/clusters/gcp_spec.rb b/spec/features/projects/clusters/gcp_spec.rb index 31c0735f577..0ebe3459a65 100644 --- a/spec/features/projects/clusters/gcp_spec.rb +++ b/spec/features/projects/clusters/gcp_spec.rb @@ -20,10 +20,6 @@ feature 'Gcp Cluster', :js do .to receive(:token_in_session).and_return('token') allow_any_instance_of(Projects::ClustersController) .to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s) - allow_any_instance_of(Projects::Clusters::GcpController) - .to receive(:token_in_session).and_return('token') - allow_any_instance_of(Projects::Clusters::GcpController) - .to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s) end context 'when user does not have a cluster and visits cluster index page' do |