diff options
Diffstat (limited to 'spec/controllers/admin/clusters_controller_spec.rb')
-rw-r--r-- | spec/controllers/admin/clusters_controller_spec.rb | 239 |
1 files changed, 0 insertions, 239 deletions
diff --git a/spec/controllers/admin/clusters_controller_spec.rb b/spec/controllers/admin/clusters_controller_spec.rb index fed9d2e8588..ca2b50b529c 100644 --- a/spec/controllers/admin/clusters_controller_spec.rb +++ b/spec/controllers/admin/clusters_controller_spec.rb @@ -102,87 +102,6 @@ RSpec.describe Admin::ClustersController do end end - describe 'GET #new' do - let(:user) { admin } - - def go(provider: 'gcp') - get :new, params: { provider: provider } - end - - include_examples ':certificate_based_clusters feature flag controller responses' do - let(:subject) { go } - end - - describe 'functionality for new cluster' do - context 'when omniauth has been configured' do - let(:key) { 'secret-key' } - let(:session_key_for_redirect_uri) do - GoogleApi::CloudPlatform::Client.session_key_for_redirect_uri(key) - end - - context 'when selected provider is gke and no valid gcp token exists' do - it 'redirects to gcp authorize_url' do - go - - expect(response).to redirect_to(assigns(:authorize_url)) - end - end - end - - context 'when omniauth has not configured' do - before do - stub_omniauth_setting(providers: []) - end - - it 'does not have authorize_url' do - go - - expect(assigns(:authorize_url)).to be_nil - end - end - - context 'when access token is valid' do - before do - stub_google_api_validate_token - end - - it 'has new object' do - go - - expect(assigns(:gcp_cluster)).to be_an_instance_of(Clusters::ClusterPresenter) - 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 'functionality for existing cluster' do - it 'has new object' do - go - - expect(assigns(:user_cluster)).to be_an_instance_of(Clusters::ClusterPresenter) - end - end - - include_examples 'GET new cluster shared examples' - - describe 'security' do - it { expect { go }.to be_allowed_for(:admin) } - it { expect { go }.to be_denied_for(:user) } - it { expect { go }.to be_denied_for(:external) } - end - end - it_behaves_like 'GET #metrics_dashboard for dashboard', 'Cluster health' do let(:cluster) { create(:cluster, :instance, :provided_by_gcp) } @@ -216,164 +135,6 @@ RSpec.describe Admin::ClustersController do end end - describe 'POST #create_gcp' do - let(:legacy_abac_param) { 'true' } - let(:params) do - { - cluster: { - name: 'new-cluster', - provider_gcp_attributes: { - gcp_project_id: 'gcp-project-12345', - legacy_abac: legacy_abac_param - } - } - } - end - - def post_create_gcp - post :create_gcp, params: params - end - - include_examples ':certificate_based_clusters feature flag controller responses' do - let(:subject) { post_create_gcp } - end - - describe 'functionality' do - 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 { post_create_gcp }.to change { Clusters::Cluster.count } - .and change { Clusters::Providers::Gcp.count } - - cluster = Clusters::Cluster.instance_type.first - - expect(response).to redirect_to(admin_cluster_path(cluster)) - expect(cluster).to be_gcp - expect(cluster).to be_kubernetes - expect(cluster.provider_gcp).to be_legacy_abac - end - - context 'when legacy_abac param is false' do - let(:legacy_abac_param) { 'false' } - - it 'creates a new cluster with legacy_abac_disabled' do - expect(ClusterProvisionWorker).to receive(:perform_async) - expect { post_create_gcp }.to change { Clusters::Cluster.count } - .and change { Clusters::Providers::Gcp.count } - expect(Clusters::Cluster.instance_type.first.provider_gcp).not_to be_legacy_abac - end - 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_next_instance_of(described_class) do |instance| - allow(instance).to receive(:token_in_session).and_return('token') - allow(instance).to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s) - end - allow_next_instance_of(GoogleApi::CloudPlatform::Client) do |instance| - allow(instance).to receive(:projects_zones_clusters_create) do - double( - 'instance', - self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123', - status: 'RUNNING' - ) - end - end - - allow(WaitForClusterCreationWorker).to receive(:perform_in).and_return(nil) - end - - it { expect { post_create_gcp }.to be_allowed_for(:admin) } - it { expect { post_create_gcp }.to be_denied_for(:user) } - it { expect { post_create_gcp }.to be_denied_for(:external) } - end - end - - describe 'POST #create_aws' do - let(:params) do - { - cluster: { - name: 'new-cluster', - provider_aws_attributes: { - key_name: 'key', - role_arn: 'arn:role', - region: 'region', - vpc_id: 'vpc', - instance_type: 'instance type', - num_nodes: 3, - security_group_id: 'security group', - subnet_ids: %w(subnet1 subnet2) - } - } - } - end - - def post_create_aws - post :create_aws, params: params - end - - include_examples ':certificate_based_clusters feature flag controller responses' do - let(:subject) { post_create_aws } - end - - it 'creates a new cluster' do - expect(ClusterProvisionWorker).to receive(:perform_async) - expect { post_create_aws }.to change { Clusters::Cluster.count } - .and change { Clusters::Providers::Aws.count } - - cluster = Clusters::Cluster.instance_type.first - - expect(response).to have_gitlab_http_status(:created) - expect(response.location).to eq(admin_cluster_path(cluster)) - expect(cluster).to be_aws - expect(cluster).to be_kubernetes - end - - context 'params are invalid' do - let(:params) do - { - cluster: { name: '' } - } - end - - it 'does not create a cluster' do - expect { post_create_aws }.not_to change { Clusters::Cluster.count } - - expect(response).to have_gitlab_http_status(:unprocessable_entity) - expect(response.media_type).to eq('application/json') - expect(response.body).to include('is invalid') - end - end - - describe 'security' do - before do - allow(WaitForClusterCreationWorker).to receive(:perform_in) - end - - it { expect { post_create_aws }.to be_allowed_for(:admin) } - it { expect { post_create_aws }.to be_denied_for(:user) } - it { expect { post_create_aws }.to be_denied_for(:external) } - end - end - describe 'POST #create_user' do let(:params) do { |