debian-mirror-gitlab/spec/controllers/projects/clusters_controller_spec.rb

656 lines
21 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2023-06-20 00:43:36 +05:30
RSpec.describe Projects::ClustersController, feature_category: :deployment_management do
2018-03-17 18:26:18 +05:30
include AccessMatchersForController
include GoogleApi::CloudPlatformHelpers
2018-12-13 13:39:08 +05:30
include KubernetesHelpers
2018-03-17 18:26:18 +05:30
2023-05-08 21:46:49 +05:30
let_it_be_with_reload(:project) { create(:project) }
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
let(:user) { create(:user) }
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
before do
project.add_maintainer(user)
sign_in(user)
end
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
describe 'GET index' do
def go(params = {})
2019-02-15 15:39:39 +05:30
get :index, params: params.reverse_merge(namespace_id: project.namespace.to_param, project_id: project)
2018-12-13 13:39:08 +05:30
end
describe 'functionality' do
2018-03-17 18:26:18 +05:30
context 'when project has one or more clusters' do
let!(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
2018-05-01 15:08:00 +05:30
let!(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, :production_environment, projects: [project]) }
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
include_examples ':certificate_based_clusters feature flag index responses' do
let(:subject) { go }
end
2020-05-24 23:13:21 +05:30
it 'lists available clusters and renders html' do
2018-03-17 18:26:18 +05:30
go
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
expect(assigns(:clusters)).to match_array([enabled_cluster, disabled_cluster])
end
2020-05-24 23:13:21 +05:30
it 'lists available clusters with json serializer' do
go(format: :json)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('cluster_list')
end
2020-06-23 00:09:42 +05:30
it 'sets the polling interval header for json requests' do
go(format: :json)
expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['Poll-Interval']).to eq("10000")
end
2018-03-17 18:26:18 +05:30
context 'when page is specified' do
let(:last_page) { project.clusters.page.total_pages }
2020-05-24 23:13:21 +05:30
let(:total_count) { project.clusters.page.total_count }
2018-03-17 18:26:18 +05:30
before do
2020-05-24 23:13:21 +05:30
create_list(:cluster, 30, :provided_by_gcp, :production_environment, projects: [project])
2018-03-17 18:26:18 +05:30
end
it 'redirects to the page' do
2020-05-24 23:13:21 +05:30
expect(last_page).to be > 1
2018-12-13 13:39:08 +05:30
go(page: last_page)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:clusters).current_page).to eq(last_page)
end
2020-05-24 23:13:21 +05:30
it 'displays cluster list for associated page' do
expect(last_page).to be > 1
go(page: last_page, format: :json)
expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['X-Page'].to_i).to eq(last_page)
expect(response.headers['X-Total'].to_i).to eq(total_count)
end
2018-03-17 18:26:18 +05:30
end
end
context 'when project does not have a cluster' do
it 'returns an empty state page' do
go
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index, partial: :empty_state)
expect(assigns(:clusters)).to eq([])
end
end
end
describe 'security' do
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
2020-04-22 19:07:51 +05:30
it 'is allowed for admin when admin mode enabled', :enable_admin_mode do
expect { go }.to be_allowed_for(:admin)
end
2020-05-24 23:13:21 +05:30
2020-04-22 19:07:51 +05:30
it 'is disabled for admin when admin mode disabled' do
expect { go }.to be_denied_for(:admin)
end
2020-05-24 23:13:21 +05:30
2018-03-17 18:26:18 +05:30
it { expect { go }.to be_allowed_for(:owner).of(project) }
2018-11-18 11:00:15 +05:30
it { expect { go }.to be_allowed_for(:maintainer).of(project) }
2022-04-04 11:22:00 +05:30
it { expect { go }.to be_allowed_for(:developer).of(project) }
2018-03-17 18:26:18 +05:30
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
2018-12-13 13:39:08 +05:30
end
2018-03-17 18:26:18 +05:30
2020-07-28 23:09:34 +05:30
describe 'GET #prometheus_proxy' do
let(:proxyable) do
create(:cluster, :provided_by_gcp, projects: [project])
end
it_behaves_like 'metrics dashboard prometheus api proxy' do
let(:proxyable_params) do
{
id: proxyable.id.to_s,
namespace_id: project.namespace.full_path,
2023-07-09 08:55:56 +05:30
project_id: project.path
2020-07-28 23:09:34 +05:30
}
end
context 'with anonymous user' do
let(:prometheus_body) { nil }
before do
sign_out(user)
end
it 'redirects to signin page' do
get :prometheus_proxy, params: prometheus_proxy_params
expect(response).to redirect_to(new_user_session_path)
end
end
2023-05-08 21:46:49 +05:30
context 'with a public project' do
before do
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED)
end
context 'with guest user' do
let(:prometheus_body) { nil }
before do
project.add_guest(user)
end
it 'returns 404' do
get :prometheus_proxy, params: prometheus_proxy_params
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
2020-07-28 23:09:34 +05:30
end
end
it_behaves_like 'GET #metrics_dashboard for dashboard', 'Cluster health' do
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let(:metrics_dashboard_req_params) do
{
id: cluster.id,
namespace_id: project.namespace.full_path,
2023-07-09 08:55:56 +05:30
project_id: project.path
2020-07-28 23:09:34 +05:30
}
end
end
2018-11-08 19:23:39 +05:30
describe 'POST create for existing cluster' do
let(:params) do
{
cluster: {
name: 'new-cluster',
2019-07-31 22:56:46 +05:30
managed: '1',
2018-11-08 19:23:39 +05:30
platform_kubernetes_attributes: {
api_url: 'http://my-url',
token: 'test',
namespace: 'aaa'
}
}
}
end
2018-12-13 13:39:08 +05:30
def go
2019-02-15 15:39:39 +05:30
post :create_user, params: params.merge(namespace_id: project.namespace, project_id: project)
2018-12-13 13:39:08 +05:30
end
2018-11-08 19:23:39 +05:30
2022-05-07 20:08:51 +05:30
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
2018-12-13 13:39:08 +05:30
describe 'functionality' do
2018-11-08 19:23:39 +05:30
context 'when creates a cluster' do
it 'creates a new cluster' do
expect { go }.to change { Clusters::Cluster.count }
.and change { Clusters::Platforms::Kubernetes.count }
2018-11-20 20:47:30 +05:30
2018-11-08 19:23:39 +05:30
expect(response).to redirect_to(project_cluster_path(project, project.clusters.first))
2018-11-20 20:47:30 +05:30
expect(project.clusters.first).to be_user
expect(project.clusters.first).to be_kubernetes
2021-01-03 14:25:43 +05:30
expect(project.clusters.first).to be_namespace_per_environment
2018-11-20 20:47:30 +05:30
end
end
context 'when creates a RBAC-enabled cluster' do
let(:params) do
{
cluster: {
name: 'new-cluster',
platform_kubernetes_attributes: {
api_url: 'http://my-url',
token: 'test',
namespace: 'aaa',
authorization_type: 'rbac'
}
}
}
end
it 'creates a new cluster' do
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))
2019-07-31 22:56:46 +05:30
cluster = project.clusters.first
expect(cluster).to be_user
expect(cluster).to be_kubernetes
expect(cluster).to be_platform_kubernetes_rbac
2021-01-03 14:25:43 +05:30
expect(cluster).to be_namespace_per_environment
2019-07-31 22:56:46 +05:30
end
end
context 'when creates a user-managed cluster' do
let(:params) do
{
cluster: {
name: 'new-cluster',
managed: '0',
platform_kubernetes_attributes: {
api_url: 'http://my-url',
token: 'test',
namespace: 'aaa',
authorization_type: 'rbac'
}
}
}
end
it 'creates a new user-managed cluster' do
go
cluster = project.clusters.first
expect(cluster.managed?).to be_falsy
2018-11-08 19:23:39 +05:30
end
end
end
describe 'security' do
2018-12-13 13:39:08 +05:30
before do
stub_kubeclient_get_namespace('https://kubernetes.example.com', namespace: 'my-namespace')
end
2020-04-22 19:07:51 +05:30
it 'is allowed for admin when admin mode enabled', :enable_admin_mode do
expect { go }.to be_allowed_for(:admin)
end
2022-08-27 11:52:29 +05:30
2020-04-22 19:07:51 +05:30
it 'is disabled for admin when admin mode disabled' do
expect { go }.to be_denied_for(:admin)
end
2022-08-27 11:52:29 +05:30
2019-12-26 22:10:19 +05:30
it { expect { go }.to be_allowed_for(:owner).of(project) }
it { expect { go }.to be_allowed_for(:maintainer).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
end
2020-01-01 13:55:28 +05:30
describe 'DELETE clear cluster cache' do
let(:cluster) { create(:cluster, :project, projects: [project]) }
let!(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, cluster: cluster) }
2019-12-26 22:10:19 +05:30
def go
2020-01-01 13:55:28 +05:30
delete :clear_cache,
params: {
namespace_id: project.namespace,
project_id: project,
id: cluster
}
2019-12-26 22:10:19 +05:30
end
2022-05-07 20:08:51 +05:30
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
2020-01-01 13:55:28 +05:30
it 'deletes the namespaces associated with the cluster' do
expect { go }.to change { Clusters::KubernetesNamespace.count }
2019-12-26 22:10:19 +05:30
2020-01-01 13:55:28 +05:30
expect(response).to redirect_to(project_cluster_path(project, cluster))
expect(cluster.kubernetes_namespaces).to be_empty
2019-12-26 22:10:19 +05:30
end
describe 'security' do
2020-04-22 19:07:51 +05:30
it 'is allowed for admin when admin mode enabled', :enable_admin_mode do
expect { go }.to be_allowed_for(:admin)
end
2022-08-27 11:52:29 +05:30
2020-04-22 19:07:51 +05:30
it 'is disabled for admin when admin mode disabled' do
expect { go }.to be_denied_for(:admin)
end
2022-08-27 11:52:29 +05:30
2019-12-26 22:10:19 +05:30
it { expect { go }.to be_allowed_for(:owner).of(project) }
it { expect { go }.to be_allowed_for(:maintainer).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
end
2018-12-13 13:39:08 +05:30
describe 'GET cluster_status' do
2018-03-17 18:26:18 +05:30
let(:cluster) { create(:cluster, :providing_by_gcp, projects: [project]) }
2018-12-13 13:39:08 +05:30
def go
get :cluster_status,
2019-02-15 15:39:39 +05:30
params: {
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: cluster
},
2018-12-13 13:39:08 +05:30
format: :json
end
2018-03-17 18:26:18 +05:30
2022-05-07 20:08:51 +05:30
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
2018-12-13 13:39:08 +05:30
describe 'functionality' do
2018-03-17 18:26:18 +05:30
it "responds with matching schema" do
go
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('cluster_status')
end
end
describe 'security' do
2020-04-22 19:07:51 +05:30
it 'is allowed for admin when admin mode enabled', :enable_admin_mode do
expect { go }.to be_allowed_for(:admin)
end
2022-08-27 11:52:29 +05:30
2020-04-22 19:07:51 +05:30
it 'is disabled for admin when admin mode disabled' do
expect { go }.to be_denied_for(:admin)
end
2022-08-27 11:52:29 +05:30
2018-03-17 18:26:18 +05:30
it { expect { go }.to be_allowed_for(:owner).of(project) }
2018-11-18 11:00:15 +05:30
it { expect { go }.to be_allowed_for(:maintainer).of(project) }
2018-03-17 18:26:18 +05:30
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
end
describe 'GET show' do
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
2021-04-29 21:17:54 +05:30
def go(tab: nil)
2018-12-13 13:39:08 +05:30
get :show,
2019-02-15 15:39:39 +05:30
params: {
namespace_id: project.namespace,
project_id: project,
2021-04-29 21:17:54 +05:30
id: cluster,
tab: tab
2019-02-15 15:39:39 +05:30
}
2018-12-13 13:39:08 +05:30
end
2018-03-17 18:26:18 +05:30
2022-05-07 20:08:51 +05:30
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
2018-12-13 13:39:08 +05:30
describe 'functionality' do
2023-07-09 08:55:56 +05:30
context 'when remove_monitor_metrics FF is disabled' do
before do
stub_feature_flags(remove_monitor_metrics: false)
end
2021-04-29 21:17:54 +05:30
2023-07-09 08:55:56 +05:30
render_views
2018-03-17 18:26:18 +05:30
2023-07-09 08:55:56 +05:30
it "renders view" do
go
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:cluster)).to eq(cluster)
end
it 'renders integration tab view' do
go(tab: 'integrations')
expect(response).to render_template('clusters/clusters/_integrations')
expect(response).to have_gitlab_http_status(:ok)
end
2018-03-17 18:26:18 +05:30
end
2021-04-29 21:17:54 +05:30
2023-07-09 08:55:56 +05:30
context 'when remove_monitor_metrics FF is enabled' do
render_views
2021-04-29 21:17:54 +05:30
2023-07-09 08:55:56 +05:30
it 'renders details tab view', :aggregate_failures do
go(tab: 'integrations')
expect(response).to render_template('clusters/clusters/_details')
expect(response).to have_gitlab_http_status(:ok)
end
2021-04-29 21:17:54 +05:30
end
2018-03-17 18:26:18 +05:30
end
describe 'security' do
2020-04-22 19:07:51 +05:30
it 'is allowed for admin when admin mode enabled', :enable_admin_mode do
expect { go }.to be_allowed_for(:admin)
end
2022-08-27 11:52:29 +05:30
2020-04-22 19:07:51 +05:30
it 'is disabled for admin when admin mode disabled' do
expect { go }.to be_denied_for(:admin)
end
2022-08-27 11:52:29 +05:30
2018-03-17 18:26:18 +05:30
it { expect { go }.to be_allowed_for(:owner).of(project) }
2018-11-18 11:00:15 +05:30
it { expect { go }.to be_allowed_for(:maintainer).of(project) }
2022-04-04 11:22:00 +05:30
it { expect { go }.to be_allowed_for(:developer).of(project) }
2018-03-17 18:26:18 +05:30
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
end
describe 'PUT update' do
2019-02-15 15:39:39 +05:30
def go(format: :html)
2023-05-27 22:25:52 +05:30
put :update, params: params.merge(
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: cluster,
format: format
)
2019-02-15 15:39:39 +05:30
end
before do
stub_kubeclient_get_namespace('https://kubernetes.example.com', namespace: 'my-namespace')
end
let(:cluster) { create(:cluster, :provided_by_user, projects: [project]) }
2019-01-03 12:48:30 +05:30
let(:params) do
{
cluster: {
enabled: false,
name: 'my-new-cluster-name',
2019-09-04 21:01:54 +05:30
managed: false,
2021-01-03 14:25:43 +05:30
namespace_per_environment: false,
2019-01-03 12:48:30 +05:30
platform_kubernetes_attributes: {
namespace: 'my-namespace'
}
}
}
end
2022-05-07 20:08:51 +05:30
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
2019-02-15 15:39:39 +05:30
it "updates and redirects back to show page" do
go
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
cluster.reload
expect(response).to redirect_to(project_cluster_path(project, cluster))
expect(flash[:notice]).to eq('Kubernetes cluster was successfully updated.')
expect(cluster.enabled).to be_falsey
expect(cluster.name).to eq('my-new-cluster-name')
2019-09-04 21:01:54 +05:30
expect(cluster).not_to be_managed
2021-01-03 14:25:43 +05:30
expect(cluster).not_to be_namespace_per_environment
2019-02-15 15:39:39 +05:30
expect(cluster.platform_kubernetes.namespace).to eq('my-namespace')
2018-12-13 13:39:08 +05:30
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
context 'when format is json' do
context 'when changing parameters' do
context 'when valid parameters are used' do
let(:params) do
{
cluster: {
enabled: false,
name: 'my-new-cluster-name',
2019-09-04 21:01:54 +05:30
managed: false,
2019-02-15 15:39:39 +05:30
platform_kubernetes_attributes: {
namespace: 'my-namespace'
2018-03-17 18:26:18 +05:30
}
}
2019-02-15 15:39:39 +05:30
}
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it "updates and redirects back to show page" do
go(format: :json)
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
cluster.reload
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:no_content)
2019-02-15 15:39:39 +05:30
expect(cluster.enabled).to be_falsey
expect(cluster.name).to eq('my-new-cluster-name')
2019-09-04 21:01:54 +05:30
expect(cluster).not_to be_managed
2019-02-15 15:39:39 +05:30
expect(cluster.platform_kubernetes.namespace).to eq('my-namespace')
2018-03-17 18:26:18 +05:30
end
2019-02-15 15:39:39 +05:30
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
context 'when invalid parameters are used' do
let(:params) do
{
cluster: {
enabled: false,
platform_kubernetes_attributes: {
namespace: 'my invalid namespace #@'
2018-03-17 18:26:18 +05:30
}
}
2019-02-15 15:39:39 +05:30
}
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it "rejects changes" do
go(format: :json)
2018-03-17 18:26:18 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:bad_request)
2018-03-17 18:26:18 +05:30
end
end
end
end
describe 'security' do
2019-12-21 20:55:43 +05:30
let_it_be(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
2018-03-17 18:26:18 +05:30
2020-04-22 19:07:51 +05:30
it 'is allowed for admin when admin mode enabled', :enable_admin_mode do
expect { go }.to be_allowed_for(:admin)
end
2022-08-27 11:52:29 +05:30
2020-04-22 19:07:51 +05:30
it 'is disabled for admin when admin mode disabled' do
expect { go }.to be_denied_for(:admin)
end
2022-08-27 11:52:29 +05:30
2018-03-17 18:26:18 +05:30
it { expect { go }.to be_allowed_for(:owner).of(project) }
2018-11-18 11:00:15 +05:30
it { expect { go }.to be_allowed_for(:maintainer).of(project) }
2018-03-17 18:26:18 +05:30
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
end
describe 'DELETE destroy' do
2018-12-13 13:39:08 +05:30
let!(:cluster) { create(:cluster, :provided_by_gcp, :production_environment, projects: [project]) }
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
def go
delete :destroy,
2019-02-15 15:39:39 +05:30
params: {
namespace_id: project.namespace,
project_id: project,
id: cluster
}
2018-12-13 13:39:08 +05:30
end
2018-03-17 18:26:18 +05:30
2022-05-07 20:08:51 +05:30
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
2018-12-13 13:39:08 +05:30
describe 'functionality' do
2018-03-17 18:26:18 +05:30
context 'when cluster is provided by GCP' do
context 'when cluster is created' do
it "destroys and redirects back to clusters list" do
expect { go }
.to change { Clusters::Cluster.count }.by(-1)
.and change { Clusters::Platforms::Kubernetes.count }.by(-1)
.and change { Clusters::Providers::Gcp.count }.by(-1)
expect(response).to redirect_to(project_clusters_path(project))
expect(flash[:notice]).to eq('Kubernetes cluster integration was successfully removed.')
end
end
context 'when cluster is being created' do
2018-11-08 19:23:39 +05:30
let!(:cluster) { create(:cluster, :providing_by_gcp, :production_environment, projects: [project]) }
2018-03-17 18:26:18 +05:30
it "destroys and redirects back to clusters list" do
expect { go }
.to change { Clusters::Cluster.count }.by(-1)
.and change { Clusters::Providers::Gcp.count }.by(-1)
expect(response).to redirect_to(project_clusters_path(project))
expect(flash[:notice]).to eq('Kubernetes cluster integration was successfully removed.')
end
end
end
context 'when cluster is provided by user' do
2018-11-08 19:23:39 +05:30
let!(:cluster) { create(:cluster, :provided_by_user, :production_environment, projects: [project]) }
2018-03-17 18:26:18 +05:30
it "destroys and redirects back to clusters list" do
expect { go }
.to change { Clusters::Cluster.count }.by(-1)
.and change { Clusters::Platforms::Kubernetes.count }.by(-1)
.and change { Clusters::Providers::Gcp.count }.by(0)
expect(response).to redirect_to(project_clusters_path(project))
expect(flash[:notice]).to eq('Kubernetes cluster integration was successfully removed.')
end
end
end
describe 'security' do
2019-12-21 20:55:43 +05:30
let_it_be(:cluster) { create(:cluster, :provided_by_gcp, :production_environment, projects: [project]) }
2018-03-17 18:26:18 +05:30
2020-04-22 19:07:51 +05:30
it 'is allowed for admin when admin mode enabled', :enable_admin_mode do
expect { go }.to be_allowed_for(:admin)
end
2022-08-27 11:52:29 +05:30
2020-04-22 19:07:51 +05:30
it 'is disabled for admin when admin mode disabled' do
expect { go }.to be_denied_for(:admin)
end
2022-08-27 11:52:29 +05:30
2018-03-17 18:26:18 +05:30
it { expect { go }.to be_allowed_for(:owner).of(project) }
2018-11-18 11:00:15 +05:30
it { expect { go }.to be_allowed_for(:maintainer).of(project) }
2018-03-17 18:26:18 +05:30
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
2018-12-13 13:39:08 +05:30
end
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
context 'no project_id param' do
it 'does not respond to any action without project_id param' do
expect { get :index }.to raise_error(ActionController::UrlGenerationError)
2018-03-17 18:26:18 +05:30
end
end
end