diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/controllers/admin | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) | |
download | gitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/controllers/admin')
5 files changed, 48 insertions, 259 deletions
diff --git a/spec/controllers/admin/clusters/applications_controller_spec.rb b/spec/controllers/admin/clusters/applications_controller_spec.rb deleted file mode 100644 index d1ca64d6bd2..00000000000 --- a/spec/controllers/admin/clusters/applications_controller_spec.rb +++ /dev/null @@ -1,139 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Admin::Clusters::ApplicationsController do - include AccessMatchersForController - - def current_application - Clusters::Cluster::APPLICATIONS[application] - end - - shared_examples 'a secure endpoint' do - it { expect { subject }.to be_allowed_for(:admin) } - it { expect { subject }.to be_denied_for(:user) } - it { expect { subject }.to be_denied_for(:external) } - end - - let(:cluster) { create(:cluster, :instance, :provided_by_gcp) } - - describe 'POST create' do - subject do - post :create, params: params - end - - let(:application) { 'ingress' } - let(:params) { { application: application, id: cluster.id } } - - describe 'functionality' do - let(:admin) { create(:admin) } - - before do - sign_in(admin) - end - - it 'schedule an application installation' do - expect(ClusterInstallAppWorker).to receive(:perform_async).with(application, anything).once - - expect { subject }.to change { current_application.count } - expect(response).to have_gitlab_http_status(:no_content) - expect(cluster.application_ingress).to be_scheduled - end - - context 'when cluster do not exists' do - before do - cluster.destroy! - end - - it 'return 404' do - expect { subject }.not_to change { current_application.count } - expect(response).to have_gitlab_http_status(:not_found) - end - end - - context 'when application is unknown' do - let(:application) { 'unkwnown-app' } - - it 'return 404' do - is_expected.to have_gitlab_http_status(:not_found) - end - end - - context 'when application is already installing' do - before do - create(:clusters_applications_ingress, :installing, cluster: cluster) - end - - it 'returns 400' do - is_expected.to have_gitlab_http_status(:bad_request) - end - end - end - - describe 'security' do - before do - allow(ClusterInstallAppWorker).to receive(:perform_async) - end - - it_behaves_like 'a secure endpoint' - end - end - - describe 'PATCH update' do - subject do - patch :update, params: params - end - - let!(:application) { create(:clusters_applications_cert_manager, :installed, cluster: cluster) } - let(:application_name) { application.name } - let(:params) { { application: application_name, id: cluster.id, email: "new-email@example.com" } } - - describe 'functionality' do - let(:admin) { create(:admin) } - - before do - sign_in(admin) - end - - context "when cluster and app exists" do - it "schedules an application update" do - expect(ClusterPatchAppWorker).to receive(:perform_async).with(application.name, anything).once - - is_expected.to have_gitlab_http_status(:no_content) - - expect(cluster.application_cert_manager).to be_scheduled - end - end - - context 'when cluster do not exists' do - before do - cluster.destroy! - end - - it { is_expected.to have_gitlab_http_status(:not_found) } - end - - context 'when application is unknown' do - let(:application_name) { 'unkwnown-app' } - - it { is_expected.to have_gitlab_http_status(:not_found) } - end - - context 'when application is already scheduled' do - before do - application.make_scheduled! - end - - it { is_expected.to have_gitlab_http_status(:bad_request) } - end - end - - describe 'security' do - before do - allow(ClusterPatchAppWorker).to receive(:perform_async) - end - - it_behaves_like 'a secure endpoint' - end - end -end diff --git a/spec/controllers/admin/integrations_controller_spec.rb b/spec/controllers/admin/integrations_controller_spec.rb index 5a68bb2749b..64ae2a95b4e 100644 --- a/spec/controllers/admin/integrations_controller_spec.rb +++ b/spec/controllers/admin/integrations_controller_spec.rb @@ -43,15 +43,15 @@ RSpec.describe Admin::IntegrationsController do stub_jira_integration_test allow(PropagateIntegrationWorker).to receive(:perform_async) - put :update, params: { id: integration.class.to_param, service: { url: url } } + put :update, params: { id: integration.class.to_param, service: params } end context 'valid params' do - let(:url) { 'https://jira.gitlab-example.com' } + let(:params) { { url: 'https://jira.gitlab-example.com', password: 'password' } } it 'updates the integration' do expect(response).to have_gitlab_http_status(:found) - expect(integration.reload.url).to eq(url) + expect(integration.reload).to have_attributes(params) end it 'calls to PropagateIntegrationWorker' do @@ -60,12 +60,12 @@ RSpec.describe Admin::IntegrationsController do end context 'invalid params' do - let(:url) { 'invalid' } + let(:params) { { url: 'invalid', password: 'password' } } it 'does not update the integration' do expect(response).to have_gitlab_http_status(:ok) expect(response).to render_template(:edit) - expect(integration.reload.url).not_to eq(url) + expect(integration.reload).not_to have_attributes(params) end it 'does not call to PropagateIntegrationWorker' do @@ -97,4 +97,40 @@ RSpec.describe Admin::IntegrationsController do .and change { Integrations::Jira.inherit_from_id(integration.id).count }.by(-1) end end + + describe '#overrides' do + let_it_be(:instance_integration) { create(:bugzilla_integration, :instance) } + let_it_be(:non_overridden_integration) { create(:bugzilla_integration, inherit_from_id: instance_integration.id) } + let_it_be(:overridden_integration) { create(:bugzilla_integration) } + let_it_be(:overridden_other_integration) { create(:confluence_integration) } + + subject do + get :overrides, params: { id: instance_integration.class.to_param }, format: format + end + + context 'when format is JSON' do + let(:format) { :json } + + include_context 'JSON response' + + it 'returns projects with overrides', :aggregate_failures do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to contain_exactly(a_hash_including('full_name' => overridden_integration.project.full_name)) + end + end + + context 'when format is HTML' do + let(:format) { :html } + + it 'renders template' do + subject + + expect(response).to render_template 'shared/integrations/overrides' + expect(assigns(:integration)).to eq(instance_integration) + end + end + end end diff --git a/spec/controllers/admin/runners_controller_spec.rb b/spec/controllers/admin/runners_controller_spec.rb index b5e7af2c012..8e57b4f03a7 100644 --- a/spec/controllers/admin/runners_controller_spec.rb +++ b/spec/controllers/admin/runners_controller_spec.rb @@ -12,42 +12,11 @@ RSpec.describe Admin::RunnersController do describe '#index' do render_views - before do - stub_feature_flags(runner_list_view_vue_ui: false) - end - it 'lists all runners' do get :index expect(response).to have_gitlab_http_status(:ok) - end - - it 'avoids N+1 queries', :request_store do - get :index - - control_count = ActiveRecord::QueryRecorder.new { get :index }.count - - create_list(:ci_runner, 5, :tagged_only) - - # There is still an N+1 query for `runner.builds.count` - # We also need to add 1 because it takes 2 queries to preload tags - # also looking for token nonce requires database queries - expect { get :index }.not_to exceed_query_limit(control_count + 16) - - expect(response).to have_gitlab_http_status(:ok) - expect(response.body).to have_content('tag1') - expect(response.body).to have_content('tag2') - end - - it 'paginates runners' do - stub_const("Admin::RunnersController::NUMBER_OF_RUNNERS_PER_PAGE", 1) - - create(:ci_runner) - - get :index - - expect(response).to have_gitlab_http_status(:ok) - expect(assigns(:runners).count).to be(1) + expect(response).to render_template(:index) end end diff --git a/spec/controllers/admin/services_controller_spec.rb b/spec/controllers/admin/services_controller_spec.rb deleted file mode 100644 index 06ff8f0db94..00000000000 --- a/spec/controllers/admin/services_controller_spec.rb +++ /dev/null @@ -1,75 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Admin::ServicesController do - let(:admin) { create(:admin) } - - before do - sign_in(admin) - end - - describe 'GET #edit' do - let(:service) do - create(:jira_integration, :template) - end - - it 'successfully displays the template' do - get :edit, params: { id: service.id } - - expect(response).to have_gitlab_http_status(:ok) - end - - context 'when integration does not exists' do - it 'redirects to the admin application integration page' do - get :edit, params: { id: 'invalid' } - - expect(response).to redirect_to(admin_application_settings_services_path) - end - end - - context 'when instance integration exists' do - before do - create(:jira_integration, :instance) - end - - it 'redirects to the admin application integration page' do - get :edit, params: { id: service.id } - - expect(response).to redirect_to(admin_application_settings_services_path) - end - end - end - - describe "#update" do - let(:project) { create(:project) } - let!(:service_template) do - Integrations::Redmine.create!( - project: nil, - active: false, - template: true, - properties: { - project_url: 'http://abc', - issues_url: 'http://abc', - new_issue_url: 'http://abc' - } - ) - end - - it 'calls the propagation worker when service is active' do - expect(PropagateServiceTemplateWorker).to receive(:perform_async).with(service_template.id) - - put :update, params: { id: service_template.id, service: { active: true } } - - expect(response).to have_gitlab_http_status(:found) - end - - it 'does not call the propagation worker when service is not active' do - expect(PropagateServiceTemplateWorker).not_to receive(:perform_async) - - put :update, params: { id: service_template.id, service: { properties: {} } } - - expect(response).to have_gitlab_http_status(:found) - end - end -end diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 6dc5c38cb76..6e172f53257 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -359,13 +359,12 @@ RSpec.describe Admin::UsersController do end end - describe 'PUT ban/:id' do + describe 'PUT ban/:id', :aggregate_failures do context 'when ban_user_feature_flag is enabled' do it 'bans user' do put :ban, params: { id: user.username } - user.reload - expect(user.banned?).to be_truthy + expect(user.reload.banned?).to be_truthy expect(flash[:notice]).to eq _('Successfully banned') end @@ -390,21 +389,19 @@ RSpec.describe Admin::UsersController do it 'does not ban user, renders 404' do put :ban, params: { id: user.username } - user.reload - expect(user.banned?).to be_falsey + expect(user.reload.banned?).to be_falsey expect(response).to have_gitlab_http_status(:not_found) end end end - describe 'PUT unban/:id' do + describe 'PUT unban/:id', :aggregate_failures do let(:banned_user) { create(:user, :banned) } it 'unbans user' do put :unban, params: { id: banned_user.username } - banned_user.reload - expect(banned_user.banned?).to be_falsey + expect(banned_user.reload.banned?).to be_falsey expect(flash[:notice]).to eq _('Successfully unbanned') end end @@ -419,6 +416,7 @@ RSpec.describe Admin::UsersController do put :unlock, params: { id: user.username } user.reload expect(user.access_locked?).to be_falsey + expect(flash[:notice]).to eq _('Successfully unlocked') end end |