Commit 53eebcfb authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch...

Merge branch '201995-geo-replication-secondary-fails-to-download-lfs-files-from-the-primary-s-s3-without' into 'master'

Geo: secondary fails to download LFS files from s3

Closes #201995

See merge request gitlab-org/gitlab!37008
parents 2da169cc 7e6dc430
---
title: 'Geo: Fix LFS file downloads from S3 to secondary'
merge_request: 37008
author:
type: fixed
...@@ -188,7 +188,11 @@ module Gitlab ...@@ -188,7 +188,11 @@ module Gitlab
begin begin
# Make the request # Make the request
response = ::HTTP.timeout(DOWNLOAD_TIMEOUT.dup).follow.get(url, headers: req_headers) response = ::HTTP.timeout(DOWNLOAD_TIMEOUT.dup).get(url, headers: req_headers)
if response.status.redirect?
response = ::HTTP.timeout(DOWNLOAD_TIMEOUT.dup).get(response['Location'])
end
# Check for failures # Check for failures
unless response.status.success? unless response.status.success?
......
...@@ -23,7 +23,7 @@ RSpec.describe Gitlab::Geo::Replication::BaseTransfer do ...@@ -23,7 +23,7 @@ RSpec.describe Gitlab::Geo::Replication::BaseTransfer do
end end
end end
describe 'timeout' do describe 'HTTP timeout when there are primary connection problems' do
subject do subject do
described_class.new(file_type: :avatar, file_id: 1, filename: Tempfile.new, described_class.new(file_type: :avatar, file_id: 1, filename: Tempfile.new,
expected_checksum: nil, request_data: nil, resource: nil) expected_checksum: nil, request_data: nil, resource: nil)
...@@ -94,4 +94,38 @@ RSpec.describe Gitlab::Geo::Replication::BaseTransfer do ...@@ -94,4 +94,38 @@ RSpec.describe Gitlab::Geo::Replication::BaseTransfer do
expect(subject.can_transfer?).to be_truthy expect(subject.can_transfer?).to be_truthy
end end
end end
describe '#stream_from_primary_to_object_storage' do
let_it_be(:lfs_object) { create(:lfs_object, :with_file, :correct_oid) }
let(:auth_headers) { { 'Authorization' => 'Bearer 12345' } }
let(:download_link) { 'http://download.link' }
subject do
Gitlab::Geo::Replication::LfsTransfer.new(lfs_object)
end
before do
stub_current_geo_node(secondary_node)
end
it 'downloads file successfully' do
allow_next_instance_of(Gitlab::Geo::TransferRequest) do |request|
allow(request).to receive(:headers).and_return(auth_headers)
end
stub_request(:get, primary_node.geo_transfers_url(:lfs, lfs_object.id.to_s))
.to_return(status: 302, headers: { 'Location' => download_link })
# This stub acts as assertion that auth headers are not present,
# otherwise we would get 500 error
stub_request(:get, download_link)
.with(headers: auth_headers)
.to_return(status: 500)
stub_request(:get, download_link)
.to_return(status: 200)
expect(subject.stream_from_primary_to_object_storage.success).to be_truthy
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