diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2017-08-18 14:26:11 +1100 |
---|---|---|
committer | blackst0ne <blackst0ne.ru@gmail.com> | 2017-08-18 14:26:11 +1100 |
commit | 2047991363844b4f17216f94778b432ed198a412 (patch) | |
tree | 6b90710c44dae00178ad323d796beb59737f47f1 /spec/lib/container_registry/client_spec.rb | |
parent | 7a1c5ba7471b233c994f5b5b313085d0d1292b5d (diff) | |
parent | f3203cbbc25586df622552153cc460d2f79f414e (diff) | |
download | gitlab-ce-2047991363844b4f17216f94778b432ed198a412.tar.gz |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'spec/lib/container_registry/client_spec.rb')
-rw-r--r-- | spec/lib/container_registry/client_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/lib/container_registry/client_spec.rb b/spec/lib/container_registry/client_spec.rb new file mode 100644 index 00000000000..3df33f48adb --- /dev/null +++ b/spec/lib/container_registry/client_spec.rb @@ -0,0 +1,39 @@ +# coding: utf-8 +require 'spec_helper' + +describe ContainerRegistry::Client do + let(:token) { '12345' } + let(:options) { { token: token } } + let(:client) { described_class.new("http://container-registry", options) } + + describe '#blob' do + it 'GET /v2/:name/blobs/:digest' do + stub_request(:get, "http://container-registry/v2/group/test/blobs/sha256:0123456789012345") + .with(headers: { + 'Accept' => 'application/octet-stream', + 'Authorization' => "bearer #{token}" + }) + .to_return(status: 200, body: "Blob") + + expect(client.blob('group/test', 'sha256:0123456789012345')).to eq('Blob') + end + + it 'follows 307 redirect for GET /v2/:name/blobs/:digest' do + stub_request(:get, "http://container-registry/v2/group/test/blobs/sha256:0123456789012345") + .with(headers: { + 'Accept' => 'application/octet-stream', + 'Authorization' => "bearer #{token}" + }) + .to_return(status: 307, body: "", headers: { Location: 'http://redirected' }) + # We should probably use hash_excluding here, but that requires an update to WebMock: + # https://github.com/bblimke/webmock/blob/master/lib/webmock/matchers/hash_excluding_matcher.rb + stub_request(:get, "http://redirected/") + .with { |request| !request.headers.include?('Authorization') } + .to_return(status: 200, body: "Successfully redirected") + + response = client.blob('group/test', 'sha256:0123456789012345') + + expect(response).to eq('Successfully redirected') + end + end +end |