Commit 160b4827 authored by Kamil Trzciński's avatar Kamil Trzciński

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
parents 6b3585d8 373f6a9b
......@@ -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
......
---
title: Fix `JobsController#raw` endpoint can not read traces in database
merge_request: 18101
author:
type: fixed
......@@ -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)
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment