diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /spec/controllers/projects | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'spec/controllers/projects')
13 files changed, 287 insertions, 80 deletions
diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb index 00efd7d7b56..3d12926c07a 100644 --- a/spec/controllers/projects/artifacts_controller_spec.rb +++ b/spec/controllers/projects/artifacts_controller_spec.rb @@ -26,14 +26,34 @@ RSpec.describe Projects::ArtifactsController do subject { get :index, params: { namespace_id: project.namespace, project_id: project } } context 'when feature flag is on' do + render_views + before do stub_feature_flags(artifacts_management_page: true) end - it 'renders the page' do + it 'renders the page with data for the artifacts app' do subject expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template('projects/artifacts/index') + + app = Nokogiri::HTML.parse(response.body).at_css('div#js-artifact-management') + + expect(app.attributes['data-project-path'].value).to eq(project.full_path) + expect(app.attributes['data-can-destroy-artifacts'].value).to eq('true') + end + + describe 'when user does not have permission to delete artifacts' do + let(:user) { create(:user) } + + it 'passes false to the artifacts app' do + subject + + app = Nokogiri::HTML.parse(response.body).at_css('div#js-artifact-management') + + expect(app.attributes['data-can-destroy-artifacts'].value).to eq('false') + end end end @@ -423,6 +443,16 @@ RSpec.describe Projects::ArtifactsController do end end + context 'when artifacts archive is missing' do + let!(:job) { create(:ci_build, :success, pipeline: pipeline) } + + it 'returns 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + end + end + context 'fetching an artifact of different type' do before do job.job_artifacts.each(&:destroy) diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index 12202518e1e..894f0f8354d 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -181,8 +181,6 @@ RSpec.describe Projects::ClustersController do describe 'functionality' do 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 } @@ -210,8 +208,6 @@ RSpec.describe Projects::ClustersController do end 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 } diff --git a/spec/controllers/projects/deploy_keys_controller_spec.rb b/spec/controllers/projects/deploy_keys_controller_spec.rb index fd844808d81..ec63bad22b5 100644 --- a/spec/controllers/projects/deploy_keys_controller_spec.rb +++ b/spec/controllers/projects/deploy_keys_controller_spec.rb @@ -102,7 +102,7 @@ RSpec.describe Projects::DeployKeysController do it 'shows an alert with the validations errors' do post :create, params: create_params(nil) - expect(flash[:alert]).to eq("Title can't be blank, Deploy keys projects deploy key title can't be blank") + expect(flash[:alert]).to eq("Title can't be blank") end end @@ -126,8 +126,7 @@ RSpec.describe Projects::DeployKeysController do it 'shows an alert with the validations errors' do post :create, params: create_params - expect(flash[:alert]).to eq("Fingerprint sha256 has already been taken, " \ - "Deploy keys projects deploy key fingerprint sha256 has already been taken") + expect(flash[:alert]).to eq("Fingerprint sha256 has already been taken") end end end diff --git a/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb b/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb index cc0f4a426f4..5cc6e1b1bb4 100644 --- a/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb +++ b/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::DesignManagement::Designs::ResizedImageController do +RSpec.describe Projects::DesignManagement::Designs::ResizedImageController, feature_category: :design_management do include DesignManagementTestHelpers let_it_be(:project) { create(:project, :private) } @@ -19,7 +19,7 @@ RSpec.describe Projects::DesignManagement::Designs::ResizedImageController do end describe 'GET #show' do - subject do + subject(:response) do get(:show, params: { namespace_id: project.namespace, @@ -27,12 +27,12 @@ RSpec.describe Projects::DesignManagement::Designs::ResizedImageController do design_id: design_id, sha: sha, id: size - }) + } + ) end before do sign_in(viewer) - subject end context 'when the user does not have permission' do @@ -68,8 +68,6 @@ RSpec.describe Projects::DesignManagement::Designs::ResizedImageController do let(:design_id) { 'foo' } specify do - subject - expect(response).to have_gitlab_http_status(:not_found) end end @@ -136,6 +134,24 @@ RSpec.describe Projects::DesignManagement::Designs::ResizedImageController do expect(response).to have_gitlab_http_status(:not_found) end end + + context 'when multiple design versions have the same sha hash' do + let(:sha) { newest_version.sha } + + before do + create(:design, :with_smaller_image_versions, + issue: create(:issue, project: project), + versions_count: 1, + versions_sha: sha) + end + + it 'serves the newest image' do + action = newest_version.actions.first + + expect(response.header['ETag']).to eq(etag(action)) + expect(response).to have_gitlab_http_status(:ok) + end + end end context 'when design does not have a smaller image size available' do diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index 2334521b8a8..dddefbac163 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -998,6 +998,94 @@ RSpec.describe Projects::EnvironmentsController do end end + describe '#append_info_to_payload' do + let(:search_param) { 'my search param' } + + context 'when search_environment_logging feature is disabled' do + before do + stub_feature_flags(environments_search_logging: false) + end + + it 'does not log search params in meta.environment.search' do + expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| + method.call(payload) + + expect(payload[:metadata]).not_to have_key('meta.environment.search') + expect(payload[:action]).to eq("search") + expect(payload[:controller]).to eq("Projects::EnvironmentsController") + end + + get :search, params: environment_params(format: :json, search: search_param) + end + + it 'logs params correctly when search params are missing' do + expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| + method.call(payload) + + expect(payload[:metadata]).not_to have_key('meta.environment.search') + expect(payload[:action]).to eq("search") + expect(payload[:controller]).to eq("Projects::EnvironmentsController") + end + + get :search, params: environment_params(format: :json) + end + + it 'logs params correctly when search params is empty string' do + expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| + method.call(payload) + + expect(payload[:metadata]).not_to have_key('meta.environment.search') + expect(payload[:action]).to eq("search") + expect(payload[:controller]).to eq("Projects::EnvironmentsController") + end + + get :search, params: environment_params(format: :json, search: "") + end + end + + context 'when search_environment_logging feature is enabled' do + before do + stub_feature_flags(environments_search_logging: true) + end + + it 'logs search params in meta.environment.search' do + expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| + method.call(payload) + + expect(payload[:metadata]['meta.environment.search']).to eq(search_param) + expect(payload[:action]).to eq("search") + expect(payload[:controller]).to eq("Projects::EnvironmentsController") + end + + get :search, params: environment_params(format: :json, search: search_param) + end + + it 'logs params correctly when search params are missing' do + expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| + method.call(payload) + + expect(payload[:metadata]).not_to have_key('meta.environment.search') + expect(payload[:action]).to eq("search") + expect(payload[:controller]).to eq("Projects::EnvironmentsController") + end + + get :search, params: environment_params(format: :json) + end + + it 'logs params correctly when search params is empty string' do + expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| + method.call(payload) + + expect(payload[:metadata]).not_to have_key('meta.environment.search') + expect(payload[:action]).to eq("search") + expect(payload[:controller]).to eq("Projects::EnvironmentsController") + end + + get :search, params: environment_params(format: :json, search: "") + end + end + end + def environment_params(opts = {}) opts.reverse_merge(namespace_id: project.namespace, project_id: project, diff --git a/spec/controllers/projects/group_links_controller_spec.rb b/spec/controllers/projects/group_links_controller_spec.rb index 96705d82ac5..a5c00d24e30 100644 --- a/spec/controllers/projects/group_links_controller_spec.rb +++ b/spec/controllers/projects/group_links_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::GroupLinksController do +RSpec.describe Projects::GroupLinksController, feature_category: :authentication_and_authorization do let_it_be(:group) { create(:group, :private) } let_it_be(:group2) { create(:group, :private) } let_it_be(:project) { create(:project, :private, group: group2) } @@ -60,4 +60,79 @@ RSpec.describe Projects::GroupLinksController do end end end + + describe '#destroy' do + let(:group_owner) { create(:user) } + + let(:link) do + create(:project_group_link, project: project, group: group, group_access: Gitlab::Access::DEVELOPER) + end + + subject(:destroy_link) do + post(:destroy, params: { namespace_id: project.namespace.to_param, + project_id: project.to_param, + id: link.id }) + end + + shared_examples 'success response' do + it 'deletes the project group link' do + destroy_link + + expect(response).to redirect_to(project_project_members_path(project)) + expect(response).to have_gitlab_http_status(:found) + end + end + + context 'when user is group owner' do + before do + link.group.add_owner(group_owner) + sign_in(group_owner) + end + + context 'when user is not project maintainer' do + it 'deletes the project group link and redirects to group show page' do + destroy_link + + expect(response).to redirect_to(group_path(group)) + expect(response).to have_gitlab_http_status(:found) + end + end + + context 'when user is a project maintainer' do + before do + project.add_maintainer(group_owner) + end + + it 'deletes the project group link and redirects to group show page' do + destroy_link + + expect(response).to redirect_to(group_path(group)) + expect(response).to have_gitlab_http_status(:found) + end + end + end + + context 'when user is not a group owner' do + context 'when user is a project maintainer' do + before do + sign_in(user) + end + + it_behaves_like 'success response' + end + + context 'when user is not a project maintainer' do + before do + project.add_developer(user) + sign_in(user) + end + + it 'renders 404' do + destroy_link + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + end end diff --git a/spec/controllers/projects/merge_requests/creations_controller_spec.rb b/spec/controllers/projects/merge_requests/creations_controller_spec.rb index ace8c04b819..7db708e0e78 100644 --- a/spec/controllers/projects/merge_requests/creations_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/creations_controller_spec.rb @@ -307,7 +307,7 @@ RSpec.describe Projects::MergeRequests::CreationsController do end end - describe 'GET target_projects', feature_category: :code_review do + describe 'GET target_projects', feature_category: :code_review_workflow do it 'returns target projects JSON' do get :target_projects, params: { namespace_id: project.namespace.to_param, project_id: project } diff --git a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb index 613d82efd06..4de724fd6d6 100644 --- a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb @@ -213,7 +213,6 @@ RSpec.describe Projects::MergeRequests::DiffsController do commit: nil, latest_diff: true, only_context_commits: false, - merge_conflicts_in_diff: true, merge_ref_head_diff: false } end @@ -281,7 +280,6 @@ RSpec.describe Projects::MergeRequests::DiffsController do commit: nil, latest_diff: true, only_context_commits: false, - merge_conflicts_in_diff: true, merge_ref_head_diff: nil } end @@ -303,33 +301,6 @@ RSpec.describe Projects::MergeRequests::DiffsController do commit: merge_request.diff_head_commit, latest_diff: nil, only_context_commits: false, - merge_conflicts_in_diff: true, - merge_ref_head_diff: nil - } - end - end - end - - context 'when display_merge_conflicts_in_diff is disabled' do - subject { go } - - before do - stub_feature_flags(display_merge_conflicts_in_diff: false) - end - - it_behaves_like 'serializes diffs metadata with expected arguments' do - let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiff } - let(:expected_options) do - { - merge_request: merge_request, - merge_request_diff: merge_request.merge_request_diff, - merge_request_diffs: merge_request.merge_request_diffs, - start_version: nil, - start_sha: nil, - commit: nil, - latest_diff: true, - only_context_commits: false, - merge_conflicts_in_diff: false, merge_ref_head_diff: nil } end @@ -430,6 +401,16 @@ RSpec.describe Projects::MergeRequests::DiffsController do expect(response).to have_gitlab_http_status(:ok) end + it 'measures certain parts of the request' do + allow(Gitlab::Metrics).to receive(:measure).and_call_original + expect(Gitlab::Metrics).to receive(:measure).with(:diffs_unfoldable_positions).and_call_original + expect(Gitlab::Metrics).to receive(:measure).with(:diffs_unfold).and_call_original + expect(Gitlab::Metrics).to receive(:measure).with(:diffs_write_cache).and_call_original + expect(Gitlab::Metrics).to receive(:measure).with(:diffs_render).and_call_original + + subject + end + it 'tracks mr_diffs event' do expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) .to receive(:track_mr_diffs_action) @@ -488,7 +469,6 @@ RSpec.describe Projects::MergeRequests::DiffsController do commit: nil, diff_view: :inline, merge_ref_head_diff: nil, - merge_conflicts_in_diff: true, pagination_data: { total_pages: nil }.merge(pagination_data) @@ -607,21 +587,6 @@ RSpec.describe Projects::MergeRequests::DiffsController do it_behaves_like 'successful request' end - context 'when display_merge_conflicts_in_diff is disabled' do - before do - stub_feature_flags(display_merge_conflicts_in_diff: false) - end - - subject { go } - - it_behaves_like 'serializes diffs with expected arguments' do - let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } - let(:expected_options) { collection_arguments(total_pages: 20).merge(merge_conflicts_in_diff: false) } - end - - it_behaves_like 'successful request' - end - it_behaves_like 'forked project with submodules' it_behaves_like 'cached diff collection' diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index a93dc806283..095775b0ddd 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::MergeRequestsController, feature_category: :code_review do +RSpec.describe Projects::MergeRequestsController, feature_category: :code_review_workflow do include ProjectForksHelper include Gitlab::Routing using RSpec::Parameterized::TableSyntax @@ -229,6 +229,16 @@ RSpec.describe Projects::MergeRequestsController, feature_category: :code_review expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-diff:") end + + context 'when there is no diff' do + it 'renders 404' do + merge_request.merge_request_diff.destroy! + + go(format: :diff) + + expect(response).to have_gitlab_http_status(:not_found) + end + end end describe "as patch" do @@ -237,6 +247,16 @@ RSpec.describe Projects::MergeRequestsController, feature_category: :code_review expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-format-patch:") end + + context 'when there is no diff' do + it 'renders 404' do + merge_request.merge_request_diff.destroy! + + go(format: :patch) + + expect(response).to have_gitlab_http_status(:not_found) + end + end end end @@ -2132,12 +2152,13 @@ RSpec.describe Projects::MergeRequestsController, feature_category: :code_review create(:protected_branch, project: project, name: merge_request.source_branch, allow_force_push: false) end - it 'returns 404' do + it 'returns 403' do expect_rebase_worker_for(user).never post_rebase - expect(response).to have_gitlab_http_status(:not_found) + expect(response).to have_gitlab_http_status(:forbidden) + expect(json_response['merge_error']).to eq('Source branch is protected from force push') end end @@ -2153,12 +2174,13 @@ RSpec.describe Projects::MergeRequestsController, feature_category: :code_review forked_project.add_reporter(user) end - it 'returns 404' do + it 'returns 403' do expect_rebase_worker_for(user).never post_rebase - expect(response).to have_gitlab_http_status(:not_found) + expect(response).to have_gitlab_http_status(:forbidden) + expect(json_response['merge_error']).to eq('Cannot push to source branch') end end diff --git a/spec/controllers/projects/pages_domains_controller_spec.rb b/spec/controllers/projects/pages_domains_controller_spec.rb index b29bbef0c40..9cc740fcbef 100644 --- a/spec/controllers/projects/pages_domains_controller_spec.rb +++ b/spec/controllers/projects/pages_domains_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::PagesDomainsController do +RSpec.describe Projects::PagesDomainsController, feature_category: :pages do let(:user) { create(:user) } let(:project) { create(:project) } let!(:pages_domain) { create(:pages_domain, project: project) } @@ -70,6 +70,7 @@ RSpec.describe Projects::PagesDomainsController do project_id: project.id, namespace_id: project.namespace.id, root_namespace_id: project.root_namespace.id, + domain_id: kind_of(Numeric), domain: pages_domain_params[:domain] ) @@ -119,6 +120,7 @@ RSpec.describe Projects::PagesDomainsController do project_id: project.id, namespace_id: project.namespace.id, root_namespace_id: project.root_namespace.id, + domain_id: pages_domain.id, domain: pages_domain.domain ) end @@ -226,6 +228,7 @@ RSpec.describe Projects::PagesDomainsController do project_id: project.id, namespace_id: project.namespace.id, root_namespace_id: project.root_namespace.id, + domain_id: pages_domain.id, domain: pages_domain.domain ) @@ -251,6 +254,7 @@ RSpec.describe Projects::PagesDomainsController do project_id: project.id, namespace_id: project.namespace.id, root_namespace_id: project.root_namespace.id, + domain_id: pages_domain.id, domain: pages_domain.domain ) end diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index f66e4b133ca..3d1d28945f7 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -84,6 +84,13 @@ RSpec.describe Projects::PipelinesController do end context 'when performing gitaly calls', :request_store do + before do + # To prevent double writes / fallback read due to MultiStore which is failing the `Gitlab::GitalyClient + # .get_request_count` expectation. + stub_feature_flags(use_primary_store_as_default_for_repository_cache: false) + stub_feature_flags(use_primary_and_secondary_stores_for_repository_cache: false) + end + it 'limits the Gitaly requests' do # Isolate from test preparation (Repository#exists? is also cached in RequestStore) RequestStore.end! diff --git a/spec/controllers/projects/protected_branches_controller_spec.rb b/spec/controllers/projects/protected_branches_controller_spec.rb index 14728618633..6778d4100b8 100644 --- a/spec/controllers/projects/protected_branches_controller_spec.rb +++ b/spec/controllers/projects/protected_branches_controller_spec.rb @@ -33,21 +33,26 @@ RSpec.describe Projects::ProtectedBranchesController do let(:create_params) { attributes_for(:protected_branch).merge(access_level_params) } - it 'creates the protected branch rule' do - expect do - post(:create, params: project_params.merge(protected_branch: create_params)) - end.to change(ProtectedBranch, :count).by(1) - end + describe "created successfully" do + using RSpec::Parameterized::TableSyntax - context 'when repository is empty' do - let(:project) { empty_project } + let(:protected_branch) { create(:protected_branch, project: ref_project) } + let(:project_params) { { namespace_id: ref_project.namespace.to_param, project_id: ref_project } } + + subject { post(:create, params: project_params.merge(protected_branch: create_params), format: format) } - it 'creates the protected branch rule' do - expect do - post(:create, params: project_params.merge(protected_branch: create_params)) - end.to change(ProtectedBranch, :count).by(1) + where(:format, :ref_project, :response_status) do + :html | ref(:project) | :found + :html | ref(:empty_project) | :found + :json | ref(:project) | :ok + :json | ref(:empty_project) | :ok + end - expect(response).to have_gitlab_http_status(:found) + with_them do + it 'creates a protected branch' do + expect { subject }.to change(ProtectedBranch, :count).by(1) + expect(response).to have_gitlab_http_status(response_status) + end end end diff --git a/spec/controllers/projects/releases/evidences_controller_spec.rb b/spec/controllers/projects/releases/evidences_controller_spec.rb index 68433969d69..879cbc543e9 100644 --- a/spec/controllers/projects/releases/evidences_controller_spec.rb +++ b/spec/controllers/projects/releases/evidences_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::Releases::EvidencesController do +RSpec.describe Projects::Releases::EvidencesController, :with_license do let!(:project) { create(:project, :repository, :public) } let_it_be(:private_project) { create(:project, :repository, :private) } let_it_be(:developer) { create(:user) } |