Commit d112e364 authored by Robert May's avatar Robert May

Merge branch 'master' into 'master'

Skip LFS fragment on redirect

See merge request gitlab-org/gitlab!65751
parents c6dd3a0a 559e7a5c
...@@ -61,8 +61,10 @@ module Projects ...@@ -61,8 +61,10 @@ module Projects
def download_and_save_file!(file) def download_and_save_file!(file)
digester = Digest::SHA256.new digester = Digest::SHA256.new
fetch_file do |fragment| fetch_file do |fragment|
digester << fragment if digest_fragment?(fragment)
file.write(fragment) digester << fragment
file.write(fragment)
end
raise_size_error! if file.size > lfs_size raise_size_error! if file.size > lfs_size
end end
...@@ -71,6 +73,10 @@ module Projects ...@@ -71,6 +73,10 @@ module Projects
raise_oid_error! if digester.hexdigest != lfs_oid raise_oid_error! if digester.hexdigest != lfs_oid
end end
def digest_fragment?(fragment)
fragment.http_response.is_a?(Net::HTTPSuccess)
end
def download_options def download_options
http_options = { headers: lfs_headers, stream_body: true } http_options = { headers: lfs_headers, stream_body: true }
......
...@@ -106,6 +106,26 @@ RSpec.describe Projects::LfsPointers::LfsDownloadService do ...@@ -106,6 +106,26 @@ RSpec.describe Projects::LfsPointers::LfsDownloadService do
end end
end end
context 'when file download returns a redirect' do
let(:redirect_link) { 'http://external-link' }
before do
stub_full_request(download_link).to_return(status: 301, body: 'You are being redirected', headers: { 'Location' => redirect_link } )
stub_full_request(redirect_link).to_return(body: lfs_content)
end
it_behaves_like 'lfs object is created'
it 'correctly stores lfs object' do
subject.execute
new_lfs_object = LfsObject.first
expect(new_lfs_object).to have_attributes(oid: oid, size: size)
expect(File.binread(new_lfs_object.file.file.file)).to eq lfs_content
end
end
context 'when downloaded lfs file has a different size' do context 'when downloaded lfs file has a different size' do
let(:size) { 1 } let(:size) { 1 }
......
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