2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::Registry::TagsController do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :private) }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:repository) do
|
|
|
|
create(:container_repository, name: 'image', project: project)
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:service) { double('service') }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
stub_container_registry_config(enabled: true)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe 'GET index' do
|
|
|
|
let(:tags) do
|
|
|
|
Array.new(40) { |i| "tag#{i}" }
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
2019-03-02 22:35:43 +05:30
|
|
|
stub_container_registry_tags(repository: /image/, tags: tags, with_manifest: true)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when user can control the registry' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'receive a list of tags' do
|
|
|
|
get_tags
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to match_response_schema('registry/tags')
|
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
it 'tracks the event' do
|
|
|
|
expect(Gitlab::Tracking).to receive(:event).with(anything, 'list_tags', {})
|
|
|
|
|
|
|
|
get_tags
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can read the registry' do
|
|
|
|
before do
|
|
|
|
project.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'receive a list of tags' do
|
|
|
|
get_tags
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to match_response_schema('registry/tags')
|
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user does not have access to registry' do
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not receive a list of tags' do
|
|
|
|
get_tags
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_tags
|
2019-02-15 15:39:39 +05:30
|
|
|
get :index, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
repository_id: repository
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST destroy' do
|
|
|
|
context 'when user has access to registry' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
context 'when there is matching tag present' do
|
|
|
|
before do
|
2019-12-21 20:55:43 +05:30
|
|
|
stub_container_registry_tags(repository: repository.path, tags: %w[rc1], with_manifest: true)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'makes it possible to delete regular tag' do
|
2019-12-21 20:55:43 +05:30
|
|
|
expect_delete_tags(%w[rc1])
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
destroy_tag('rc1')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'makes it possible to delete a tag that ends with a dot' do
|
2019-12-21 20:55:43 +05:30
|
|
|
expect_delete_tags(%w[test.])
|
|
|
|
|
|
|
|
destroy_tag('test.')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tracks the event' do
|
|
|
|
expect_delete_tags(%w[test.])
|
|
|
|
expect(controller).to receive(:track_event).with(:delete_tag)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
destroy_tag('test.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def destroy_tag(name)
|
2019-02-15 15:39:39 +05:30
|
|
|
post :destroy, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
repository_id: repository,
|
|
|
|
id: name
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
format: :json
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
describe 'POST bulk_destroy' do
|
|
|
|
context 'when user has access to registry' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is matching tag present' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(repository: repository.path, tags: %w[rc1 test.])
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:tags) { %w[tc1 test.] }
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'makes it possible to delete tags in bulk' do
|
2019-12-21 20:55:43 +05:30
|
|
|
expect_delete_tags(tags)
|
|
|
|
|
|
|
|
bulk_destroy_tags(tags)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tracks the event' do
|
|
|
|
expect_delete_tags(tags)
|
|
|
|
expect(Gitlab::Tracking).to receive(:event).with(anything, 'delete_tag_bulk', {})
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
bulk_destroy_tags(tags)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def bulk_destroy_tags(names)
|
|
|
|
post :bulk_destroy, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
repository_id: repository,
|
|
|
|
ids: names
|
|
|
|
},
|
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
def expect_delete_tags(tags, status = :success)
|
|
|
|
expect(service).to receive(:execute).with(repository) { { status: status } }
|
|
|
|
expect(Projects::ContainerRepository::DeleteTagsService).to receive(:new).with(repository.project, user, tags: tags) { service }
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|