Commit 94f27b5a authored by Shinya Maeda's avatar Shinya Maeda

Add integration specs for EE version. Raise an error when htto request fails.

parent d40e8a95
...@@ -7,6 +7,7 @@ module Gitlab ...@@ -7,6 +7,7 @@ module Gitlab
class HttpIO class HttpIO
BUFFER_SIZE = 128.kilobytes BUFFER_SIZE = 128.kilobytes
InvalidURLError = Class.new(StandardError)
FailedToGetChunkError = Class.new(StandardError) FailedToGetChunkError = Class.new(StandardError)
attr_reader :uri, :size attr_reader :uri, :size
...@@ -16,6 +17,8 @@ module Gitlab ...@@ -16,6 +17,8 @@ module Gitlab
alias_method :pos, :tell alias_method :pos, :tell
def initialize(url, size) def initialize(url, size)
raise InvalidURLError unless ::Gitlab::UrlSanitizer.valid?(url)
@uri = URI(url) @uri = URI(url)
@size = size @size = size
@tell = 0 @tell = 0
...@@ -82,8 +85,6 @@ module Gitlab ...@@ -82,8 +85,6 @@ module Gitlab
out = out[0, length] if length && out.length > length out = out[0, length] if length && out.length > length
out out
rescue FailedToGetChunkError
nil
end end
def readline def readline
...@@ -104,8 +105,6 @@ module Gitlab ...@@ -104,8 +105,6 @@ module Gitlab
end end
out out
rescue FailedToGetChunkError
nil
end end
def write(data) def write(data)
......
...@@ -2,10 +2,55 @@ require 'spec_helper' ...@@ -2,10 +2,55 @@ require 'spec_helper'
describe Projects::JobsController do describe Projects::JobsController do
include ApiHelpers include ApiHelpers
include HttpIOHelpers
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let(:pipeline) { create(:ci_pipeline, project: project) } let(:pipeline) { create(:ci_pipeline, project: project) }
describe 'GET trace.json' do
context 'when trace artifact is in ObjectStorage' do
let!(:job) { create(:ci_build, :success, :trace_artifact, pipeline: pipeline) }
before do
allow_any_instance_of(JobArtifactUploader).to receive(:file_storage?) { false }
allow_any_instance_of(JobArtifactUploader).to receive(:url) { remote_trace_url }
allow_any_instance_of(JobArtifactUploader).to receive(:size) { remote_trace_size }
end
context 'when there are no network issues' do
before do
stub_remote_trace_ok
get_trace
end
it 'returns a trace' do
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['id']).to eq job.id
expect(json_response['status']).to eq job.status
expect(json_response['html']).to eq(job.trace.html)
end
end
context 'when there is a network issue' do
before do
stub_remote_trace_ng
end
it 'returns a trace' do
expect { get_trace }.to raise_error(Gitlab::Ci::Trace::HttpIO::FailedToGetChunkError)
end
end
end
def get_trace
get :trace, namespace_id: project.namespace,
project_id: project,
id: job.id,
format: :json
end
end
describe 'GET raw' do describe 'GET raw' do
subject do subject do
post :raw, namespace_id: project.namespace, post :raw, namespace_id: project.namespace,
......
require 'spec_helper' require 'spec_helper'
describe API::Jobs do describe API::Jobs do
include HttpIOHelpers
set(:project) do set(:project) do
create(:project, :repository, public_builds: false) create(:project, :repository, public_builds: false)
end end
...@@ -451,6 +453,22 @@ describe API::Jobs do ...@@ -451,6 +453,22 @@ describe API::Jobs do
end end
context 'authorized user' do context 'authorized user' do
context 'when trace is in ObjectStorage' do
let!(:job) { create(:ci_build, :trace_artifact, pipeline: pipeline) }
before do
stub_remote_trace_ok
allow_any_instance_of(JobArtifactUploader).to receive(:file_storage?) { false }
allow_any_instance_of(JobArtifactUploader).to receive(:url) { remote_trace_url }
allow_any_instance_of(JobArtifactUploader).to receive(:size) { remote_trace_size }
end
it 'returns specific job trace' do
expect(response).to have_gitlab_http_status(200)
expect(response.body).to eq(job.trace.raw)
end
end
context 'when trace is artifact' do context 'when trace is artifact' do
let(:job) { create(:ci_build, :trace_artifact, pipeline: pipeline) } let(:job) { create(:ci_build, :trace_artifact, pipeline: pipeline) }
......
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