diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/controllers/projects/merge_requests_controller_spec.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/controllers/projects/merge_requests_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/merge_requests_controller_spec.rb | 307 |
1 files changed, 279 insertions, 28 deletions
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index aaeaf53d100..7d9e42fcc2d 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -935,34 +935,6 @@ describe Projects::MergeRequestsController do }]) end end - - context 'when feature flag :ci_expose_arbitrary_artifacts_in_mr is disabled' do - let(:job_options) do - { - artifacts: { - paths: ['ci_artifacts.txt'], - expose_as: 'Exposed artifact' - } - } - end - let(:report) { double } - - before do - stub_feature_flags(ci_expose_arbitrary_artifacts_in_mr: false) - end - - it 'does not send polling interval' do - expect(Gitlab::PollingInterval).not_to receive(:set_header) - - subject - end - - it 'returns 204 HTTP status' do - subject - - expect(response).to have_gitlab_http_status(:no_content) - end - end end context 'when pipeline does not have jobs with exposed artifacts' do @@ -1114,6 +1086,150 @@ describe Projects::MergeRequestsController do end end + describe 'GET terraform_reports' do + let(:merge_request) do + create(:merge_request, + :with_merge_request_pipeline, + target_project: project, + source_project: project) + end + + let(:pipeline) do + create(:ci_pipeline, + :success, + :with_terraform_reports, + project: merge_request.source_project, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha) + end + + before do + allow_any_instance_of(MergeRequest) + .to receive(:find_terraform_reports) + .and_return(report) + + allow_any_instance_of(MergeRequest) + .to receive(:actual_head_pipeline) + .and_return(pipeline) + end + + subject do + get :terraform_reports, params: { + namespace_id: project.namespace.to_param, + project_id: project, + id: merge_request.iid + }, + format: :json + end + + describe 'permissions on a public project with private CI/CD' do + let(:project) { create :project, :repository, :public, :builds_private } + let(:report) { { status: :parsed, data: [] } } + + context 'while signed out' do + before do + sign_out(user) + end + + it 'responds with a 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + expect(response.body).to be_blank + end + end + + context 'while signed in as an unrelated user' do + before do + sign_in(create(:user)) + end + + it 'responds with a 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + expect(response.body).to be_blank + end + end + end + + context 'when pipeline has jobs with terraform reports' do + before do + allow_next_instance_of(MergeRequest) do |merge_request| + allow(merge_request).to receive(:has_terraform_reports?).and_return(true) + end + end + + context 'when processing terraform reports is in progress' do + let(:report) { { status: :parsing } } + + it 'sends polling interval' do + expect(Gitlab::PollingInterval).to receive(:set_header) + + subject + end + + it 'returns 204 HTTP status' do + subject + + expect(response).to have_gitlab_http_status(:no_content) + end + end + + context 'when processing terraform reports is completed' do + let(:report) { { status: :parsed, data: pipeline.terraform_reports.plans } } + + it 'returns terraform reports' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to match( + a_hash_including( + 'tfplan.json' => hash_including( + 'create' => 0, + 'delete' => 0, + 'update' => 1 + ) + ) + ) + end + end + + context 'when user created corrupted terraform reports' do + let(:report) { { status: :error, status_reason: 'Failed to parse terraform reports' } } + + it 'does not send polling interval' do + expect(Gitlab::PollingInterval).not_to receive(:set_header) + + subject + end + + it 'returns 400 HTTP status' do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response).to eq({ 'status_reason' => 'Failed to parse terraform reports' }) + end + end + end + + context 'when pipeline does not have jobs with terraform reports' do + before do + allow_next_instance_of(MergeRequest) do |merge_request| + allow(merge_request).to receive(:has_terraform_reports?).and_return(false) + end + end + + let(:report) { { status: :error } } + + it 'returns error' do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + end + describe 'GET test_reports' do let(:merge_request) do create(:merge_request, @@ -1225,6 +1341,141 @@ describe Projects::MergeRequestsController do end end + describe 'GET accessibility_reports' do + let(:merge_request) do + create(:merge_request, + :with_diffs, + :with_merge_request_pipeline, + target_project: project, + source_project: project + ) + end + + let(:pipeline) do + create(:ci_pipeline, + :success, + project: merge_request.source_project, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha) + end + + before do + allow_any_instance_of(MergeRequest) + .to receive(:compare_accessibility_reports) + .and_return(accessibility_comparison) + + allow_any_instance_of(MergeRequest) + .to receive(:actual_head_pipeline) + .and_return(pipeline) + end + + subject do + get :accessibility_reports, params: { + namespace_id: project.namespace.to_param, + project_id: project, + id: merge_request.iid + }, + format: :json + end + + context 'permissions on a public project with private CI/CD' do + let(:project) { create(:project, :repository, :public, :builds_private) } + let(:accessibility_comparison) { { status: :parsed, data: { summary: 1 } } } + + context 'while signed out' do + before do + sign_out(user) + end + + it 'responds with a 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + expect(response.body).to be_blank + end + end + + context 'while signed in as an unrelated user' do + before do + sign_in(create(:user)) + end + + it 'responds with a 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + expect(response.body).to be_blank + end + end + end + + context 'when feature flag is disabled' do + let(:accessibility_comparison) { { status: :parsed, data: { summary: 1 } } } + + before do + stub_feature_flags(accessibility_report_view: false) + end + + it 'returns 204 HTTP status' do + subject + + expect(response).to have_gitlab_http_status(:no_content) + end + end + + context 'when pipeline has jobs with accessibility reports' do + before do + allow_any_instance_of(MergeRequest) + .to receive(:has_accessibility_reports?) + .and_return(true) + end + + context 'when processing accessibility reports is in progress' do + let(:accessibility_comparison) { { status: :parsing } } + + it 'sends polling interval' do + expect(Gitlab::PollingInterval).to receive(:set_header) + + subject + end + + it 'returns 204 HTTP status' do + subject + + expect(response).to have_gitlab_http_status(:no_content) + end + end + + context 'when processing accessibility reports is completed' do + let(:accessibility_comparison) { { status: :parsed, data: { summary: 1 } } } + + it 'returns accessibility reports' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to eq({ 'summary' => 1 }) + end + end + + context 'when user created corrupted accessibility reports' do + let(:accessibility_comparison) { { status: :error, status_reason: 'This merge request does not have accessibility reports' } } + + it 'does not send polling interval' do + expect(Gitlab::PollingInterval).not_to receive(:set_header) + + subject + end + + it 'returns 400 HTTP status' do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response).to eq({ 'status_reason' => 'This merge request does not have accessibility reports' }) + end + end + end + end + describe 'POST remove_wip' do before do merge_request.title = merge_request.wip_title |