diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/controllers/groups | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/controllers/groups')
13 files changed, 313 insertions, 24 deletions
diff --git a/spec/controllers/groups/boards_controller_spec.rb b/spec/controllers/groups/boards_controller_spec.rb index 6201cddecb0..ca4931bdc90 100644 --- a/spec/controllers/groups/boards_controller_spec.rb +++ b/spec/controllers/groups/boards_controller_spec.rb @@ -16,6 +16,15 @@ RSpec.describe Groups::BoardsController do expect { list_boards }.to change(group.boards, :count).by(1) end + it 'pushes swimlanes_buffered_rendering feature flag' do + allow(controller).to receive(:push_frontend_feature_flag).and_call_original + + expect(controller).to receive(:push_frontend_feature_flag) + .with(:swimlanes_buffered_rendering, group, default_enabled: :yaml) + + list_boards + end + context 'when format is HTML' do it 'renders template' do list_boards @@ -98,6 +107,15 @@ RSpec.describe Groups::BoardsController do describe 'GET show' do let!(:board) { create(:board, group: group) } + it 'pushes swimlanes_buffered_rendering feature flag' do + allow(controller).to receive(:push_frontend_feature_flag).and_call_original + + expect(controller).to receive(:push_frontend_feature_flag) + .with(:swimlanes_buffered_rendering, group, default_enabled: :yaml) + + read_board board: board + end + context 'when format is HTML' do it 'renders template' do expect { read_board board: board }.to change(BoardGroupRecentVisit, :count).by(1) diff --git a/spec/controllers/groups/clusters_controller_spec.rb b/spec/controllers/groups/clusters_controller_spec.rb index 1334372a1f5..93c560b4753 100644 --- a/spec/controllers/groups/clusters_controller_spec.rb +++ b/spec/controllers/groups/clusters_controller_spec.rb @@ -641,21 +641,31 @@ RSpec.describe Groups::ClustersController do describe 'GET show' do let(:cluster) { create(:cluster, :provided_by_gcp, cluster_type: :group_type, groups: [group]) } - def go + def go(tab: nil) get :show, params: { group_id: group, - id: cluster + id: cluster, + tab: tab } end describe 'functionality' do + render_views + 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', :aggregate_failures do + go(tab: 'integrations') + + expect(response).to render_template('clusters/clusters/_integrations') + expect(response).to have_gitlab_http_status(:ok) + end end describe 'security' do diff --git a/spec/controllers/groups/dependency_proxy_auth_controller_spec.rb b/spec/controllers/groups/dependency_proxy_auth_controller_spec.rb index 857e0570621..f67b2022219 100644 --- a/spec/controllers/groups/dependency_proxy_auth_controller_spec.rb +++ b/spec/controllers/groups/dependency_proxy_auth_controller_spec.rb @@ -31,6 +31,7 @@ RSpec.describe Groups::DependencyProxyAuthController do context 'with valid JWT' do let_it_be(:user) { create(:user) } + let(:jwt) { build_jwt(user) } let(:token_header) { "Bearer #{jwt.encoded}" } @@ -65,6 +66,7 @@ RSpec.describe Groups::DependencyProxyAuthController do context 'expired token' do let_it_be(:user) { create(:user) } + let(:jwt) { build_jwt(user, expire_time: Time.zone.now - 1.hour) } let(:token_header) { "Bearer #{jwt.encoded}" } diff --git a/spec/controllers/groups/dependency_proxy_for_containers_controller_spec.rb b/spec/controllers/groups/dependency_proxy_for_containers_controller_spec.rb index 83775dcdbdf..9f30a850ca2 100644 --- a/spec/controllers/groups/dependency_proxy_for_containers_controller_spec.rb +++ b/spec/controllers/groups/dependency_proxy_for_containers_controller_spec.rb @@ -7,6 +7,7 @@ RSpec.describe Groups::DependencyProxyForContainersController do include DependencyProxyHelpers let_it_be(:user) { create(:user) } + let(:group) { create(:group) } let(:token_response) { { status: :success, token: 'abcd1234' } } let(:jwt) { build_jwt(user) } @@ -102,6 +103,7 @@ RSpec.describe Groups::DependencyProxyForContainersController do describe 'GET #manifest' do let_it_be(:manifest) { create(:dependency_proxy_manifest) } + let(:pull_response) { { status: :success, manifest: manifest } } before do @@ -182,6 +184,7 @@ RSpec.describe Groups::DependencyProxyForContainersController do describe 'GET #blob' do let_it_be(:blob) { create(:dependency_proxy_blob) } + let(:blob_sha) { blob.file_name.sub('.gz', '') } let(:blob_response) { { status: :success, blob: blob } } diff --git a/spec/controllers/groups/group_links_controller_spec.rb b/spec/controllers/groups/group_links_controller_spec.rb index a2f7161ca41..94d3c1ffa0f 100644 --- a/spec/controllers/groups/group_links_controller_spec.rb +++ b/spec/controllers/groups/group_links_controller_spec.rb @@ -9,16 +9,17 @@ RSpec.describe Groups::GroupLinksController do let(:group_member) { create(:user) } let!(:project) { create(:project, group: shared_group) } - around do |example| - travel_to DateTime.new(2019, 4, 1) { example.run } - end - before do + travel_to DateTime.new(2019, 4, 1) sign_in(user) shared_with_group.add_developer(group_member) end + after do + travel_back + end + shared_examples 'placeholder is passed as `id` parameter' do |action| it 'returns a 404' do post( diff --git a/spec/controllers/groups/group_members_controller_spec.rb b/spec/controllers/groups/group_members_controller_spec.rb index ff7a7f55863..19655687028 100644 --- a/spec/controllers/groups/group_members_controller_spec.rb +++ b/spec/controllers/groups/group_members_controller_spec.rb @@ -9,8 +9,12 @@ RSpec.describe Groups::GroupMembersController do let(:group) { create(:group, :public) } let(:membership) { create(:group_member, group: group) } - around do |example| - travel_to DateTime.new(2019, 4, 1) { example.run } + before do + travel_to DateTime.new(2019, 4, 1) + end + + after do + travel_back end describe 'GET index' do @@ -288,7 +292,9 @@ RSpec.describe Groups::GroupMembersController do end describe 'DELETE destroy' do - let(:member) { create(:group_member, :developer, group: group) } + let(:sub_group) { create(:group, parent: group) } + let!(:member) { create(:group_member, :developer, group: group) } + let!(:sub_member) { create(:group_member, :developer, group: sub_group, user: member.user) } before do sign_in(user) @@ -324,9 +330,19 @@ RSpec.describe Groups::GroupMembersController do it '[HTML] removes user from members' do delete :destroy, params: { group_id: group, id: member } - expect(response).to set_flash.to 'User was successfully removed from group and any subresources.' + expect(response).to set_flash.to 'User was successfully removed from group.' + expect(response).to redirect_to(group_group_members_path(group)) + expect(group.members).not_to include member + expect(sub_group.members).to include sub_member + end + + it '[HTML] removes user from members including subgroups and projects' do + delete :destroy, params: { group_id: group, id: member, remove_sub_memberships: true } + + expect(response).to set_flash.to 'User was successfully removed from group and any subgroups and projects.' expect(response).to redirect_to(group_group_members_path(group)) expect(group.members).not_to include member + expect(sub_group.members).not_to include sub_member end it '[JS] removes user from members' do diff --git a/spec/controllers/groups/labels_controller_spec.rb b/spec/controllers/groups/labels_controller_spec.rb index b2320615778..90da40cd5f0 100644 --- a/spec/controllers/groups/labels_controller_spec.rb +++ b/spec/controllers/groups/labels_controller_spec.rb @@ -46,6 +46,24 @@ RSpec.describe Groups::LabelsController do it_behaves_like 'disabled when using an external authorization service' end + + context 'with views rendered' do + render_views + + before do + get :index, params: { group_id: group.to_param } + end + + it 'avoids N+1 queries' do + control = ActiveRecord::QueryRecorder.new(skip_cached: false) { get :index, params: { group_id: group.to_param } } + + create_list(:group_label, 3, group: group) + + # some n+1 queries still exist + expect { get :index, params: { group_id: group.to_param } }.not_to exceed_all_query_limit(control.count).with_threshold(10) + expect(assigns(:labels).count).to eq(4) + end + end end describe 'POST #toggle_subscription' do diff --git a/spec/controllers/groups/milestones_controller_spec.rb b/spec/controllers/groups/milestones_controller_spec.rb index 05e93da18e7..a3c4c47ab15 100644 --- a/spec/controllers/groups/milestones_controller_spec.rb +++ b/spec/controllers/groups/milestones_controller_spec.rb @@ -322,7 +322,7 @@ RSpec.describe Groups::MilestonesController do end context 'when requesting a redirected path' do - let(:redirect_route) { group.redirect_routes.create(path: 'old-path') } + let(:redirect_route) { group.redirect_routes.create!(path: 'old-path') } it 'redirects to the canonical path' do get :merge_requests, params: { group_id: redirect_route.path, id: title } @@ -350,7 +350,7 @@ RSpec.describe Groups::MilestonesController do end context 'when the old group path is a substring of the scheme or host' do - let(:redirect_route) { group.redirect_routes.create(path: 'http') } + let(:redirect_route) { group.redirect_routes.create!(path: 'http') } it 'does not modify the requested host' do get :merge_requests, params: { group_id: redirect_route.path, id: title } @@ -362,7 +362,7 @@ RSpec.describe Groups::MilestonesController do context 'when the old group path is substring of groups' do # I.e. /groups/oups should not become /grfoo/oups - let(:redirect_route) { group.redirect_routes.create(path: 'oups') } + let(:redirect_route) { group.redirect_routes.create!(path: 'oups') } it 'does not modify the /groups part of the path' do get :merge_requests, params: { group_id: redirect_route.path, id: title } @@ -374,7 +374,7 @@ RSpec.describe Groups::MilestonesController do context 'when the old group path is substring of groups plus the new path' do # I.e. /groups/oups/oup should not become /grfoos - let(:redirect_route) { group.redirect_routes.create(path: 'oups/oup') } + let(:redirect_route) { group.redirect_routes.create!(path: 'oups/oup') } it 'does not modify the /groups part of the path' do get :merge_requests, params: { group_id: redirect_route.path, id: title } @@ -411,7 +411,7 @@ RSpec.describe Groups::MilestonesController do end context 'when requesting a redirected path' do - let(:redirect_route) { group.redirect_routes.create(path: 'old-path') } + let(:redirect_route) { group.redirect_routes.create!(path: 'old-path') } it 'returns not found' do post :create, diff --git a/spec/controllers/groups/registry/repositories_controller_spec.rb b/spec/controllers/groups/registry/repositories_controller_spec.rb index 70125087f30..35c9a80266e 100644 --- a/spec/controllers/groups/registry/repositories_controller_spec.rb +++ b/spec/controllers/groups/registry/repositories_controller_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Groups::Registry::RepositoriesController do let_it_be(:user) { create(:user) } let_it_be(:guest) { create(:user) } let_it_be(:group, reload: true) { create(:group) } + let(:additional_parameters) { {} } subject do diff --git a/spec/controllers/groups/runners_controller_spec.rb b/spec/controllers/groups/runners_controller_spec.rb index 91ff0a53ec7..d6da9a4e8d0 100644 --- a/spec/controllers/groups/runners_controller_spec.rb +++ b/spec/controllers/groups/runners_controller_spec.rb @@ -220,7 +220,7 @@ RSpec.describe Groups::RunnersController do end it 'marks the runner as active, ticks the queue, and redirects' do - runner.update(active: false) + runner.update!(active: false) expect do post :resume, params: params @@ -231,7 +231,7 @@ RSpec.describe Groups::RunnersController do end it 'marks the project runner as active, ticks the queue, and redirects' do - runner_project.update(active: false) + runner_project.update!(active: false) expect do post :resume, params: params_runner_project @@ -248,7 +248,7 @@ RSpec.describe Groups::RunnersController do end it 'responds 404 and does not activate the runner' do - runner.update(active: false) + runner.update!(active: false) expect do post :resume, params: params @@ -259,7 +259,7 @@ RSpec.describe Groups::RunnersController do end it 'responds 404 and does not activate the project runner' do - runner_project.update(active: false) + runner_project.update!(active: false) expect do post :resume, params: params_runner_project @@ -278,7 +278,7 @@ RSpec.describe Groups::RunnersController do end it 'marks the runner as inactive, ticks the queue, and redirects' do - runner.update(active: true) + runner.update!(active: true) expect do post :pause, params: params @@ -289,7 +289,7 @@ RSpec.describe Groups::RunnersController do end it 'marks the project runner as inactive, ticks the queue, and redirects' do - runner_project.update(active: true) + runner_project.update!(active: true) expect do post :pause, params: params_runner_project @@ -306,7 +306,7 @@ RSpec.describe Groups::RunnersController do end it 'responds 404 and does not update the runner or queue' do - runner.update(active: true) + runner.update!(active: true) expect do post :pause, params: params @@ -317,7 +317,7 @@ RSpec.describe Groups::RunnersController do end it 'responds 404 and does not update the project runner or queue' do - runner_project.update(active: true) + runner_project.update!(active: true) expect do post :pause, params: params diff --git a/spec/controllers/groups/settings/applications_controller_spec.rb b/spec/controllers/groups/settings/applications_controller_spec.rb new file mode 100644 index 00000000000..0804a5536e0 --- /dev/null +++ b/spec/controllers/groups/settings/applications_controller_spec.rb @@ -0,0 +1,219 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Groups::Settings::ApplicationsController do + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:application) { create(:oauth_application, owner_id: group.id, owner_type: 'Namespace') } + + before do + sign_in(user) + end + + describe 'GET #index' do + context 'when user is owner' do + before do + group.add_owner(user) + end + + it 'renders the application form' do + get :index, params: { group_id: group } + + expect(response).to render_template :index + expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes) + end + end + + context 'when user is not owner' do + before do + group.add_maintainer(user) + end + + it 'renders a 404' do + get :index, params: { group_id: group } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + describe 'GET #edit' do + context 'when user is owner' do + before do + group.add_owner(user) + end + + it 'renders the application form' do + get :edit, params: { group_id: group, id: application.id } + + expect(response).to render_template :edit + expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes) + end + end + + context 'when user is not owner' do + before do + group.add_maintainer(user) + end + + it 'renders a 404' do + get :edit, params: { group_id: group, id: application.id } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + describe 'POST #create' do + context 'when user is owner' do + before do + group.add_owner(user) + end + + it 'creates the application' do + create_params = attributes_for(:application, trusted: false, confidential: false, scopes: ['api']) + + expect do + post :create, params: { group_id: group, doorkeeper_application: create_params } + end.to change { Doorkeeper::Application.count }.by(1) + + application = Doorkeeper::Application.last + + expect(response).to redirect_to(group_settings_application_path(group, application)) + expect(application).to have_attributes(create_params.except(:uid, :owner_type)) + end + + it 'renders the application form on errors' do + expect do + post :create, params: { group_id: group, doorkeeper_application: attributes_for(:application).merge(redirect_uri: nil) } + end.not_to change { Doorkeeper::Application.count } + + expect(response).to render_template :index + expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes) + end + + context 'when the params are for a confidential application' do + it 'creates a confidential application' do + create_params = attributes_for(:application, confidential: true, scopes: ['read_user']) + + expect do + post :create, params: { group_id: group, doorkeeper_application: create_params } + end.to change { Doorkeeper::Application.count }.by(1) + + application = Doorkeeper::Application.last + + expect(response).to redirect_to(group_settings_application_path(group, application)) + expect(application).to have_attributes(create_params.except(:uid, :owner_type)) + end + end + + context 'when scopes are not present' do + it 'renders the application form on errors' do + create_params = attributes_for(:application, trusted: true, confidential: false) + + expect do + post :create, params: { group_id: group, doorkeeper_application: create_params } + end.not_to change { Doorkeeper::Application.count } + + expect(response).to render_template :index + end + end + end + + context 'when user is not owner' do + before do + group.add_maintainer(user) + end + + it 'renders a 404' do + create_params = attributes_for(:application, trusted: true, confidential: false, scopes: ['api']) + + post :create, params: { group_id: group, doorkeeper_application: create_params } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + describe 'PATCH #update' do + context 'when user is owner' do + before do + group.add_owner(user) + end + + it 'updates the application' do + doorkeeper_params = { redirect_uri: 'http://example.com/', trusted: true, confidential: false } + + patch :update, params: { group_id: group, id: application.id, doorkeeper_application: doorkeeper_params } + + application.reload + + expect(response).to redirect_to(group_settings_application_path(group, application)) + expect(application) + .to have_attributes(redirect_uri: 'http://example.com/', trusted: false, confidential: false) + end + + it 'renders the application form on errors' do + patch :update, params: { group_id: group, id: application.id, doorkeeper_application: { redirect_uri: nil } } + + expect(response).to render_template :edit + expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes) + end + + context 'when updating the application to be confidential' do + it 'successfully sets the application to confidential' do + doorkeeper_params = { confidential: true } + + patch :update, params: { group_id: group, id: application.id, doorkeeper_application: doorkeeper_params } + + application.reload + + expect(response).to redirect_to(group_settings_application_path(group, application)) + expect(application).to be_confidential + end + end + end + + context 'when user is not owner' do + before do + group.add_maintainer(user) + end + + it 'renders a 404' do + doorkeeper_params = { redirect_uri: 'http://example.com/', trusted: true, confidential: false } + + patch :update, params: { group_id: group, id: application.id, doorkeeper_application: doorkeeper_params } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + describe 'DELETE #destroy' do + context 'when user is owner' do + before do + group.add_owner(user) + end + + it 'deletes the application' do + delete :destroy, params: { group_id: group, id: application.id } + + expect(Doorkeeper::Application.exists?(application.id)).to be_falsy + expect(response).to redirect_to(group_settings_applications_url(group)) + end + end + + context 'when user is not owner' do + before do + group.add_maintainer(user) + end + + it 'renders a 404' do + delete :destroy, params: { group_id: group, id: application.id } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end +end diff --git a/spec/controllers/groups/uploads_controller_spec.rb b/spec/controllers/groups/uploads_controller_spec.rb index ea6a5ce8841..7dafb813545 100644 --- a/spec/controllers/groups/uploads_controller_spec.rb +++ b/spec/controllers/groups/uploads_controller_spec.rb @@ -23,7 +23,7 @@ RSpec.describe Groups::UploadsController do let!(:upload) { create(:upload, :issuable_upload, :with_file, model: model) } let(:group) { model } let(:old_path) { group.to_param + 'old' } - let!(:redirect_route) { model.redirect_routes.create(path: old_path) } + let!(:redirect_route) { model.redirect_routes.create!(path: old_path) } let(:upload_path) { File.basename(upload.path) } it 'redirects to a file with the proper extension' do diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index a450a4afb02..8c0aa83b9c4 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Groups::VariablesController do let_it_be(:group) { create(:group) } let_it_be(:user) { create(:user) } let_it_be(:variable) { create(:ci_group_variable, group: group) } + let(:access_level) { :owner } before do |