2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'rejected container repository access' do |user_type, status|
|
2019-10-12 21:52:04 +05:30
|
|
|
context "for #{user_type}" do
|
|
|
|
let(:api_user) { users[user_type] }
|
|
|
|
|
|
|
|
it "returns #{status}" do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'returns repositories for allowed users' do |user_type, scope|
|
2019-10-12 21:52:04 +05:30
|
|
|
context "for #{user_type}" do
|
|
|
|
it 'returns a list of repositories' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.map { |repository| repository['id'] }).to contain_exactly(
|
|
|
|
root_repository.id, test_repository.id)
|
|
|
|
expect(response.body).not_to include('tags')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a matching schema' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to match_response_schema('registry/repositories')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with tags param' do
|
|
|
|
let(:url) { "/#{scope}s/#{object.id}/registry/repositories?tags=true" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(repository: root_repository.path, tags: %w(rootA latest), with_manifest: true)
|
|
|
|
stub_container_registry_tags(repository: test_repository.path, tags: %w(rootA latest), with_manifest: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a list of repositories and their tags' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.map { |repository| repository['id'] }).to contain_exactly(
|
|
|
|
root_repository.id, test_repository.id)
|
|
|
|
expect(response.body).to include('tags')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a matching schema' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to match_response_schema('registry/repositories')
|
|
|
|
end
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
context 'with tags_count param' do
|
|
|
|
let(:url) { "/#{scope}s/#{object.id}/registry/repositories?tags_count=true" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(repository: root_repository.path, tags: %w(rootA latest), with_manifest: true)
|
|
|
|
stub_container_registry_tags(repository: test_repository.path, tags: %w(rootA latest), with_manifest: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a list of repositories and their tags_count' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response.body).to include('tags_count')
|
|
|
|
expect(json_response[0]['tags_count']).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a matching schema' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to match_response_schema('registry/repositories')
|
|
|
|
end
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
RSpec.shared_examples 'handling network errors with the container registry' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_network_error(client_method: :repository_tags)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a connection error' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:service_unavailable)
|
|
|
|
expect(json_response['message']).to include('We are having trouble connecting to the Container Registry')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'handling graphql network errors with the container registry' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_network_error(client_method: :repository_tags)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a connection error' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect_graphql_errors_to_include('We are having trouble connecting to the Container Registry')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'not hitting graphql network errors with the container registry' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_network_error(client_method: :repository_tags)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return any error' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect_graphql_errors_to_be_empty
|
|
|
|
end
|
|
|
|
end
|