2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe Projects::Registry::RepositoriesController do
|
2020-05-24 23:13:21 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :private) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
stub_container_registry_config(enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has access to registry' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
shared_examples 'renders 200 for html and 404 for json' do
|
|
|
|
it 'successfully renders container repositories', :snowplow do
|
|
|
|
go_to_index
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2021-04-29 21:17:54 +05:30
|
|
|
# event tracked in GraphQL API: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/44926
|
|
|
|
expect_no_snowplow_event
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 for request in json format' do
|
|
|
|
go_to_index(format: :json)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
shared_examples 'renders a list of repositories' do
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when root container repository exists' do
|
|
|
|
before do
|
|
|
|
create(:container_repository, :root, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create root container repository' do
|
|
|
|
expect { go_to_index }.not_to change { ContainerRepository.all.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when root container repository is not created' do
|
|
|
|
context 'when there are tags for this repository' do
|
|
|
|
before do
|
2020-06-23 00:09:42 +05:30
|
|
|
stub_container_registry_tags(repository: :any,
|
2017-08-17 22:00:37 +05:30
|
|
|
tags: %w[rc1 latest])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a root container repository' do
|
|
|
|
expect { go_to_index }.to change { ContainerRepository.all.count }.by(1)
|
|
|
|
expect(ContainerRepository.first).to be_root_repository
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it_behaves_like 'renders 200 for html and 404 for json'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are no tags for this repository' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(repository: :any, tags: [])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not ensure root container repository' do
|
|
|
|
expect { go_to_index }.not_to change { ContainerRepository.all.count }
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it_behaves_like 'renders 200 for html and 404 for json'
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
it_behaves_like 'renders a list of repositories'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
|
|
|
it_behaves_like 'renders a list of repositories'
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe 'DELETE #destroy' do
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when root container repository exists' do
|
|
|
|
let!(:repository) do
|
|
|
|
create(:container_repository, :root, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(repository: :any, tags: [])
|
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it 'schedules a job to delete a repository' do
|
|
|
|
expect(DeleteContainerRepositoryWorker).to receive(:perform_async).with(user.id, repository.id)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
delete_repository(repository)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(repository.reload).to be_delete_scheduled
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'tracks the event', :snowplow do
|
2019-12-21 20:55:43 +05:30
|
|
|
allow(DeleteContainerRepositoryWorker).to receive(:perform_async).with(user.id, repository.id)
|
|
|
|
|
|
|
|
delete_repository(repository)
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
expect_snowplow_event(category: anything, action: 'delete_repository')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user does not have access to registry' do
|
2020-03-13 15:44:24 +05:30
|
|
|
describe 'GET #index' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'responds with 404' do
|
|
|
|
go_to_index
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not ensure root container repository' do
|
|
|
|
expect { go_to_index }.not_to change { ContainerRepository.all.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def go_to_index(format: :html, params: {} )
|
|
|
|
get :index, params: params.merge({
|
2019-02-15 15:39:39 +05:30
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project
|
2020-05-24 23:13:21 +05:30
|
|
|
}),
|
2018-03-17 18:26:18 +05:30
|
|
|
format: format
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_repository(repository)
|
2019-02-15 15:39:39 +05:30
|
|
|
delete :destroy, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: repository
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
format: :json
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|