summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-14 08:12:27 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-14 08:12:27 +0000
commit3772445de3063dda5e5fb2f21b6debf14032cc92 (patch)
tree8db2e49b644638f160392062221e6a0a56fcfd62 /spec
parent28a9333b4b418ce3f96fcd0a530d76ac86e6c4ed (diff)
downloadgitlab-ce-3772445de3063dda5e5fb2f21b6debf14032cc92.tar.gz
Add latest changes from gitlab-org/gitlab@13-11-stable-ee
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/pipelines_controller_spec.rb33
-rw-r--r--spec/presenters/ci/stage_presenter_spec.rb49
-rw-r--r--spec/support/shared_examples/lib/gitlab/middleware/read_only_gitlab_instance_shared_examples.rb52
3 files changed, 133 insertions, 1 deletions
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb
index 753223c5a4f..4a1d01f0e82 100644
--- a/spec/controllers/projects/pipelines_controller_spec.rb
+++ b/spec/controllers/projects/pipelines_controller_spec.rb
@@ -290,6 +290,39 @@ RSpec.describe Projects::PipelinesController do
end
end
+ describe 'GET #show' do
+ render_views
+
+ let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
+
+ subject { get_pipeline_html }
+
+ def get_pipeline_html
+ get :show, params: { namespace_id: project.namespace, project_id: project, id: pipeline }, format: :html
+ end
+
+ def create_build_with_artifacts(stage, stage_idx, name)
+ create(:ci_build, :artifacts, :tags, pipeline: pipeline, stage: stage, stage_idx: stage_idx, name: name)
+ end
+
+ before do
+ create_build_with_artifacts('build', 0, 'job1')
+ create_build_with_artifacts('build', 0, 'job2')
+ end
+
+ it 'avoids N+1 database queries', :request_store do
+ get_pipeline_html
+
+ control_count = ActiveRecord::QueryRecorder.new { get_pipeline_html }.count
+ expect(response).to have_gitlab_http_status(:ok)
+
+ create_build_with_artifacts('build', 0, 'job3')
+
+ expect { get_pipeline_html }.not_to exceed_query_limit(control_count)
+ expect(response).to have_gitlab_http_status(:ok)
+ end
+ end
+
describe 'GET show.json' do
let(:pipeline) { create(:ci_pipeline, project: project) }
diff --git a/spec/presenters/ci/stage_presenter_spec.rb b/spec/presenters/ci/stage_presenter_spec.rb
new file mode 100644
index 00000000000..368f03b0150
--- /dev/null
+++ b/spec/presenters/ci/stage_presenter_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::StagePresenter do
+ let(:stage) { create(:ci_stage) }
+ let(:presenter) { described_class.new(stage) }
+
+ let!(:build) { create(:ci_build, :tags, :artifacts, pipeline: stage.pipeline, stage: stage.name) }
+ let!(:retried_build) { create(:ci_build, :tags, :artifacts, :retried, pipeline: stage.pipeline, stage: stage.name) }
+
+ before do
+ create(:generic_commit_status, pipeline: stage.pipeline, stage: stage.name)
+ end
+
+ shared_examples 'preloaded associations for CI status' do
+ it 'preloads project' do
+ expect(presented_stage.association(:project)).to be_loaded
+ end
+
+ it 'preloads build pipeline' do
+ expect(presented_stage.association(:pipeline)).to be_loaded
+ end
+
+ it 'preloads build tags' do
+ expect(presented_stage.association(:tags)).to be_loaded
+ end
+
+ it 'preloads build artifacts archive' do
+ expect(presented_stage.association(:job_artifacts_archive)).to be_loaded
+ end
+
+ it 'preloads build artifacts metadata' do
+ expect(presented_stage.association(:metadata)).to be_loaded
+ end
+ end
+
+ describe '#latest_ordered_statuses' do
+ subject(:presented_stage) { presenter.latest_ordered_statuses.second }
+
+ it_behaves_like 'preloaded associations for CI status'
+ end
+
+ describe '#retried_ordered_statuses' do
+ subject(:presented_stage) { presenter.retried_ordered_statuses.first }
+
+ it_behaves_like 'preloaded associations for CI status'
+ end
+end
diff --git a/spec/support/shared_examples/lib/gitlab/middleware/read_only_gitlab_instance_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/middleware/read_only_gitlab_instance_shared_examples.rb
index 5b3d30df739..0a07a56d417 100644
--- a/spec/support/shared_examples/lib/gitlab/middleware/read_only_gitlab_instance_shared_examples.rb
+++ b/spec/support/shared_examples/lib/gitlab/middleware/read_only_gitlab_instance_shared_examples.rb
@@ -70,6 +70,14 @@ RSpec.shared_examples 'write access for a read-only GitLab instance' do
expect(subject).not_to disallow_request
end
+ it 'expects a POST internal request with trailing slash to be allowed' do
+ expect(Rails.application.routes).not_to receive(:recognize_path)
+ response = request.post("/api/#{API::API.version}/internal/")
+
+ expect(response).not_to be_redirect
+ expect(subject).not_to disallow_request
+ end
+
it 'expects a graphql request to be allowed' do
response = request.post("/api/graphql")
@@ -77,6 +85,13 @@ RSpec.shared_examples 'write access for a read-only GitLab instance' do
expect(subject).not_to disallow_request
end
+ it 'expects a graphql request with trailing slash to be allowed' do
+ response = request.post("/api/graphql/")
+
+ expect(response).not_to be_redirect
+ expect(subject).not_to disallow_request
+ end
+
context 'relative URL is configured' do
before do
stub_config_setting(relative_url_root: '/gitlab')
@@ -88,6 +103,13 @@ RSpec.shared_examples 'write access for a read-only GitLab instance' do
expect(response).not_to be_redirect
expect(subject).not_to disallow_request
end
+
+ it 'expects a graphql request with trailing slash to be allowed' do
+ response = request.post("/gitlab/api/graphql/")
+
+ expect(response).not_to be_redirect
+ expect(subject).not_to disallow_request
+ end
end
context 'sidekiq admin requests' do
@@ -119,6 +141,19 @@ RSpec.shared_examples 'write access for a read-only GitLab instance' do
expect(response).not_to be_redirect
expect(subject).not_to disallow_request
end
+
+ it 'allows requests with trailing slash' do
+ path = File.join(mounted_at, 'admin/sidekiq')
+ response = request.post("#{path}/")
+
+ expect(response).not_to be_redirect
+ expect(subject).not_to disallow_request
+
+ response = request.get("#{path}/")
+
+ expect(response).not_to be_redirect
+ expect(subject).not_to disallow_request
+ end
end
end
@@ -138,6 +173,14 @@ RSpec.shared_examples 'write access for a read-only GitLab instance' do
expect(response).not_to be_redirect
expect(subject).not_to disallow_request
end
+
+ it "expects a POST #{description} URL with trailing slash to be allowed" do
+ expect(Rails.application.routes).to receive(:recognize_path).and_call_original
+ response = request.post("#{path}/")
+
+ expect(response).not_to be_redirect
+ expect(subject).not_to disallow_request
+ end
end
where(:description, :path) do
@@ -153,11 +196,18 @@ RSpec.shared_examples 'write access for a read-only GitLab instance' do
expect(response).to be_redirect
expect(subject).to disallow_request
end
+
+ it "expects a POST #{description} URL with trailing slash not to be allowed" do
+ response = request.post("#{path}/")
+
+ expect(response).to be_redirect
+ expect(subject).to disallow_request
+ end
end
end
end
- context 'json requests to a read-only GitLab instance' do
+ context 'JSON requests to a read-only GitLab instance' do
let(:fake_app) { lambda { |env| [200, { 'Content-Type' => 'application/json' }, ['OK']] } }
let(:content_json) { { 'CONTENT_TYPE' => 'application/json' } }