Commit 959804e8 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch '259619-force-metadata-fetching' into 'master'

Force fetch metadata from object store

See merge request gitlab-org/gitlab!72294
parents 6fc25516 5cee7ee3
......@@ -50,16 +50,23 @@ module Gitlab
end
def checksum_from_google
Base64.decode64(upload_attributes[:content_md5].to_s).unpack1('H*')
content_md5 = upload_attributes.fetch(:content_md5)
Base64
.decode64(content_md5)
.unpack1('H*')
end
def checksum_from_aws
upload_attributes[:etag]
upload_attributes.fetch(:etag)
end
# Carrierwave caches attributes for the local file and does not replace
# them with the ones from object store after the upload completes.
# We need to force it to fetch them directly from the object store.
def upload_attributes
strong_memoize(:upload_attributes) do
trace_artifact.file.file.attributes
::Ci::JobArtifact.find(trace_artifact.id).file.file.attributes
end
end
end
......
......@@ -43,18 +43,30 @@ RSpec.describe Gitlab::Ci::Trace::RemoteChecksum do
end
context 'with Google as provider' do
let(:metadata) {{ content_md5: base64checksum }}
before do
spy_file = spy(:file)
expect(fetcher).to receive(:provider_google?) { true }
expect(fetcher).not_to receive(:provider_aws?) { false }
allow(spy_file).to receive(:attributes).and_return(metadata)
allow(trace_artifact.file.file)
.to receive(:attributes)
.and_return(metadata)
allow_next_found_instance_of(Ci::JobArtifact) do |trace_artifact|
allow(trace_artifact.file).to receive(:file) { spy_file }
end
end
it { is_expected.to eq(checksum) }
context 'when the response does not include :content_md5' do
let(:metadata) {{}}
it 'raises an exception' do
expect { subject }.to raise_error KeyError, /content_md5/
end
end
context 'when the response include :content_md5' do
let(:metadata) {{ content_md5: base64checksum }}
it { is_expected.to eq(checksum) }
end
end
context 'with unsupported providers' 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