summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-04-05 18:33:32 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2018-04-05 18:33:32 +0000
commit160b4827edad1984ddb4339622b93ace17870cb1 (patch)
tree2ceaf492f689cfa7a1e4fc39c4ff7685d14a3913
parent6b3585d8ea15a7ee1a5cd2f5799caace48ab0c32 (diff)
parent373f6a9bb20497eebe4cdf41be18eb2399424a59 (diff)
downloadgitlab-ce-160b4827edad1984ddb4339622b93ace17870cb1.tar.gz
Merge branch '44665-fix-db-trace-stream-by-raw-access' into 'master'
Fix `JobsController#raw` endpoint can not read traces in database Closes #44665 See merge request gitlab-org/gitlab-ce!18101
-rw-r--r--app/controllers/projects/jobs_controller.rb2
-rw-r--r--changelogs/unreleased/44665-fix-db-trace-stream-by-raw-access.yml5
-rw-r--r--lib/gitlab/ci/trace/stream.rb6
-rw-r--r--spec/controllers/projects/jobs_controller_spec.rb19
4 files changed, 29 insertions, 3 deletions
diff --git a/app/controllers/projects/jobs_controller.rb b/app/controllers/projects/jobs_controller.rb
index 85e972d9731..ac9eb2047a0 100644
--- a/app/controllers/projects/jobs_controller.rb
+++ b/app/controllers/projects/jobs_controller.rb
@@ -128,7 +128,7 @@ class Projects::JobsController < Projects::ApplicationController
if stream.file?
send_file stream.path, type: 'text/plain; charset=utf-8', disposition: 'inline'
else
- render_404
+ send_data stream.raw, type: 'text/plain; charset=utf-8', disposition: 'inline', filename: 'job.log'
end
end
end
diff --git a/changelogs/unreleased/44665-fix-db-trace-stream-by-raw-access.yml b/changelogs/unreleased/44665-fix-db-trace-stream-by-raw-access.yml
new file mode 100644
index 00000000000..4166d4fe320
--- /dev/null
+++ b/changelogs/unreleased/44665-fix-db-trace-stream-by-raw-access.yml
@@ -0,0 +1,5 @@
+---
+title: Fix `JobsController#raw` endpoint can not read traces in database
+merge_request: 18101
+author:
+type: fixed
diff --git a/lib/gitlab/ci/trace/stream.rb b/lib/gitlab/ci/trace/stream.rb
index b3fe3ef1c4d..54894a46077 100644
--- a/lib/gitlab/ci/trace/stream.rb
+++ b/lib/gitlab/ci/trace/stream.rb
@@ -8,7 +8,7 @@ module Gitlab
attr_reader :stream
- delegate :close, :tell, :seek, :size, :path, :url, :truncate, to: :stream, allow_nil: true
+ delegate :close, :tell, :seek, :size, :url, :truncate, to: :stream, allow_nil: true
delegate :valid?, to: :stream, as: :present?, allow_nil: true
@@ -25,6 +25,10 @@ module Gitlab
self.path.present?
end
+ def path
+ self.stream.path if self.stream.respond_to?(:path)
+ end
+
def limit(last_bytes = LIMIT_SIZE)
if last_bytes < size
stream.seek(-last_bytes, IO::SEEK_END)
diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb
index 31046c202e6..b9a979044fe 100644
--- a/spec/controllers/projects/jobs_controller_spec.rb
+++ b/spec/controllers/projects/jobs_controller_spec.rb
@@ -513,13 +513,30 @@ describe Projects::JobsController do
end
end
+ context 'when job has a trace in database' do
+ let(:job) { create(:ci_build, pipeline: pipeline) }
+
+ before do
+ job.update_column(:trace, 'Sample trace')
+ end
+
+ it 'send a trace file' do
+ response = subject
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response.content_type).to eq 'text/plain; charset=utf-8'
+ expect(response.body).to eq 'Sample trace'
+ end
+ end
+
context 'when job does not have a trace file' do
let(:job) { create(:ci_build, pipeline: pipeline) }
it 'returns not_found' do
response = subject
- expect(response).to have_gitlab_http_status(:not_found)
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response.body).to eq ''
end
end