2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe DependencyProxy::PullManifestService do
|
|
|
|
include DependencyProxyHelpers
|
|
|
|
|
|
|
|
let(:image) { 'alpine' }
|
|
|
|
let(:tag) { '3.9' }
|
|
|
|
let(:token) { Digest::SHA256.hexdigest('123') }
|
|
|
|
let(:manifest) { { foo: 'bar' }.to_json }
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:digest) { '12345' }
|
2021-04-17 20:07:23 +05:30
|
|
|
let(:content_type) { 'foo' }
|
|
|
|
let(:headers) do
|
|
|
|
{ 'docker-content-digest' => digest, 'content-type' => content_type }
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
subject { described_class.new(image, tag, token).execute_with_manifest(&method(:check_response)) }
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
context 'remote request is successful' do
|
|
|
|
before do
|
2021-02-22 17:27:13 +05:30
|
|
|
stub_manifest_download(image, tag, headers: headers)
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'successfully returns the manifest' do
|
|
|
|
def check_response(response)
|
|
|
|
response[:file].rewind
|
|
|
|
|
|
|
|
expect(response[:status]).to eq(:success)
|
|
|
|
expect(response[:file].read).to eq(manifest)
|
|
|
|
expect(response[:digest]).to eq(digest)
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(response[:content_type]).to eq(content_type)
|
2021-02-22 17:27:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'remote request is not found' do
|
|
|
|
before do
|
2021-02-22 17:27:13 +05:30
|
|
|
stub_manifest_download(image, tag, status: 404, body: 'Not found')
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'returns a 404 not found error' do
|
|
|
|
def check_response(response)
|
|
|
|
expect(response[:status]).to eq(:error)
|
|
|
|
expect(response[:http_status]).to eq(404)
|
|
|
|
expect(response[:message]).to eq('Not found')
|
|
|
|
end
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'net timeout exception' do
|
|
|
|
before do
|
|
|
|
manifest_link = DependencyProxy::Registry.manifest_url(image, tag)
|
|
|
|
|
|
|
|
stub_full_request(manifest_link).to_timeout
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'returns a 599 error' do
|
|
|
|
def check_response(response)
|
|
|
|
expect(response[:status]).to eq(:error)
|
|
|
|
expect(response[:http_status]).to eq(599)
|
|
|
|
expect(response[:message]).to eq('execution expired')
|
|
|
|
end
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'no block is given' do
|
|
|
|
subject { described_class.new(image, tag, token).execute_with_manifest }
|
|
|
|
|
|
|
|
it { expect { subject }.to raise_error(ArgumentError, 'Block must be provided') }
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
end
|