Commit 5e0ce238 authored by Matija Čupić's avatar Matija Čupić

Reconcile differences in lib/gitlab/ci/external

parent 797046e3
...@@ -17,10 +17,8 @@ module Gitlab ...@@ -17,10 +17,8 @@ module Gitlab
attr_reader :locations, :project, :sha attr_reader :locations, :project, :sha
def build_external_file(location) def build_external_file(location)
remote_file = Gitlab::Ci::External::File::Remote.new(location) if ::Gitlab::UrlSanitizer.valid?(location)
Gitlab::Ci::External::File::Remote.new(location)
if remote_file.valid?
remote_file
else else
options = { project: project, sha: sha } options = { project: project, sha: sha }
Gitlab::Ci::External::File::Local.new(location, options) Gitlab::Ci::External::File::Local.new(location, options)
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
external_files.each do |external_file| external_files.each do |external_file|
validate_external_file(external_file) validate_external_file(external_file)
@content.merge!(content_of(external_file)) @content.deep_merge!(content_of(external_file))
end end
append_inline_content append_inline_content
...@@ -28,16 +28,16 @@ module Gitlab ...@@ -28,16 +28,16 @@ module Gitlab
def validate_external_file(external_file) def validate_external_file(external_file)
unless external_file.valid? unless external_file.valid?
raise FileError, "External file: '#{external_file.location}' should be a valid local or remote file" raise FileError, external_file.error_message
end end
end end
def content_of(external_file) def content_of(external_file)
::Gitlab::Ci::Config::Loader.new(external_file.content).load! Gitlab::Ci::Config::Loader.new(external_file.content).load!
end end
def append_inline_content def append_inline_content
@content.merge!(@values) @content.deep_merge!(@values)
end end
def remove_include_keyword def remove_include_keyword
......
require 'fast_spec_helper' require 'spec_helper'
describe Gitlab::Ci::External::Mapper do describe Gitlab::Ci::External::Mapper do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
...@@ -25,7 +25,7 @@ describe Gitlab::Ci::External::Mapper do ...@@ -25,7 +25,7 @@ describe Gitlab::Ci::External::Mapper do
end end
it 'returns File instances' do it 'returns File instances' do
expect(subject.first).to be_an_instance_of(::Gitlab::Ci::External::File::Local) expect(subject.first).to be_an_instance_of(Gitlab::Ci::External::File::Local)
end end
end end
...@@ -47,7 +47,7 @@ describe Gitlab::Ci::External::Mapper do ...@@ -47,7 +47,7 @@ describe Gitlab::Ci::External::Mapper do
end end
it 'returns File instances' do it 'returns File instances' do
expect(subject.first).to be_an_instance_of(::Gitlab::Ci::External::File::Remote) expect(subject.first).to be_an_instance_of(Gitlab::Ci::External::File::Remote)
end end
end end
end end
......
require 'fast_spec_helper' require 'spec_helper'
describe Gitlab::Ci::External::Processor do describe Gitlab::Ci::External::Processor do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
...@@ -19,18 +19,23 @@ describe Gitlab::Ci::External::Processor do ...@@ -19,18 +19,23 @@ describe Gitlab::Ci::External::Processor do
it 'should raise an error' do it 'should raise an error' do
expect { processor.perform }.to raise_error( expect { processor.perform }.to raise_error(
described_class::FileError, described_class::FileError,
"External file: '/vendor/gitlab-ci-yml/non-existent-file.yml' should be a valid local or remote file" "Local file '/vendor/gitlab-ci-yml/non-existent-file.yml' is not valid."
) )
end end
end end
context 'when an invalid remote file is defined' do context 'when an invalid remote file is defined' do
let(:values) { { include: 'not-valid://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml', image: 'ruby:2.2' } } let(:remote_file) { 'http://doesntexist.com/.gitlab-ci-1.yml' }
let(:values) { { include: remote_file, image: 'ruby:2.2' } }
before do
WebMock.stub_request(:get, remote_file).to_raise(SocketError.new('Some HTTP error'))
end
it 'should raise an error' do it 'should raise an error' do
expect { processor.perform }.to raise_error( expect { processor.perform }.to raise_error(
described_class::FileError, described_class::FileError,
"External file: 'not-valid://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml' should be a valid local or remote file" "Remote file '#{remote_file}' is not valid."
) )
end end
end end
...@@ -85,7 +90,7 @@ describe Gitlab::Ci::External::Processor do ...@@ -85,7 +90,7 @@ describe Gitlab::Ci::External::Processor do
end end
before do before do
allow_any_instance_of(Gitlab::Ci::External::File::Local).to receive(:local_file_content).and_return(local_file_content) allow_any_instance_of(Gitlab::Ci::External::File::Local).to receive(:fetch_local_content).and_return(local_file_content)
end end
it 'should append the file to the values' do it 'should append the file to the values' do
...@@ -102,7 +107,7 @@ describe Gitlab::Ci::External::Processor do ...@@ -102,7 +107,7 @@ describe Gitlab::Ci::External::Processor do
let(:remote_file) { 'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml' } let(:remote_file) { 'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml' }
let(:external_files) do let(:external_files) do
[ [
"/spec/ee/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml", '/ee/spec/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml',
remote_file remote_file
] ]
end end
...@@ -123,8 +128,8 @@ describe Gitlab::Ci::External::Processor do ...@@ -123,8 +128,8 @@ describe Gitlab::Ci::External::Processor do
end end
before do before do
local_file_content = File.read("#{Rails.root}/spec/ee/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml") local_file_content = File.read(Rails.root.join('ee/spec/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml'))
allow_any_instance_of(Gitlab::Ci::External::File::Local).to receive(:local_file_content).and_return(local_file_content) allow_any_instance_of(Gitlab::Ci::External::File::Local).to receive(:fetch_local_content).and_return(local_file_content)
WebMock.stub_request(:get, remote_file).to_return(body: remote_file_content) WebMock.stub_request(:get, remote_file).to_return(body: remote_file_content)
end end
...@@ -143,7 +148,7 @@ describe Gitlab::Ci::External::Processor do ...@@ -143,7 +148,7 @@ describe Gitlab::Ci::External::Processor do
let(:local_file_content) { 'invalid content file ////' } let(:local_file_content) { 'invalid content file ////' }
before do before do
allow_any_instance_of(Gitlab::Ci::External::File::Local).to receive(:local_file_content).and_return(local_file_content) allow_any_instance_of(Gitlab::Ci::External::File::Local).to receive(:fetch_local_content).and_return(local_file_content)
end end
it 'should raise an error' do it 'should raise an error' do
......
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