Commit dc1749af authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'revert-b3afa361' into 'master'

Revert !72465 into 'master'"

See merge request gitlab-org/gitlab!72649
parents a06553b4 8eb7faa3
......@@ -56,20 +56,10 @@ module Gitlab
end
def download(url, upload_path)
File.open(upload_path, 'wb') do |file|
Gitlab::HTTP.get(url, stream_body: true) do |fragment|
if [301, 302, 307].include?(fragment.code)
Gitlab::Import::Logger.warn(message: "received redirect fragment", fragment_code: fragment.code)
elsif fragment.code == 200
file.write(fragment)
else
raise Gitlab::ImportExport::Error, "unsupported response downloading fragment #{fragment.code}"
end
end
File.open(upload_path, 'w') do |file|
# Download (stream) file from the uploader's location
IO.copy_stream(URI.parse(url).open, file)
end
rescue StandardError => e
@shared.error(e) # rubocop:disable Gitlab/ModuleWithInstanceVariables
raise e
end
def tar_with_options(archive:, dir:, options:)
......
......@@ -17,10 +17,6 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
def initialize
@shared = Gitlab::ImportExport::Shared.new(nil)
end
def download(url, upload_path)
super(url, upload_path)
end
end.new
end
......@@ -105,44 +101,4 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
end
end
end
describe '#download' do
before do
stub_request(:get, loc)
.to_return(
status: 200,
body: content
)
end
context 'a non-localhost uri' do
let(:loc) { 'https://gitlab.com' }
let(:content) { File.open('spec/fixtures/rails_sample.tif') }
it 'gets the contents' do
Tempfile.create("foo") do |f|
subject.download(loc, f.path)
expect(f.read).to eq(File.open('spec/fixtures/rails_sample.tif').read)
end
end
it 'streams the contents' do
expect(Gitlab::HTTP).to receive(:get).with(loc, hash_including(stream_body: true))
Tempfile.create("foo") do |f|
subject.download(loc, f.path)
end
end
end
context 'a localhost uri' do
let(:loc) { 'https://localhost:8081/foo/bar' }
let(:content) { 'foo' }
it 'throws a blocked url error' do
Tempfile.create("foo") do |f|
expect { subject.download(loc, f.path) }.to raise_error(Gitlab::HTTP::BlockedUrlError)
end
end
end
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