diff options
-rw-r--r-- | lib/container_registry/repository.rb | 2 | ||||
-rw-r--r-- | spec/features/container_registry_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/namespace_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 19 | ||||
-rw-r--r-- | spec/services/projects/destroy_service_spec.rb | 29 | ||||
-rw-r--r-- | spec/services/projects/transfer_service_spec.rb | 11 | ||||
-rw-r--r-- | spec/support/stub_gitlab_calls.rb | 6 |
7 files changed, 76 insertions, 7 deletions
diff --git a/lib/container_registry/repository.rb b/lib/container_registry/repository.rb index b30cb527b60..07cdb78264e 100644 --- a/lib/container_registry/repository.rb +++ b/lib/container_registry/repository.rb @@ -39,7 +39,7 @@ module ContainerRegistry def delete_tags return unless tags - tags.each(:delete) + tags.all?(&:delete) end def mount_blob(blob) diff --git a/spec/features/container_registry_spec.rb b/spec/features/container_registry_spec.rb index be5910e4abb..271ef883d13 100644 --- a/spec/features/container_registry_spec.rb +++ b/spec/features/container_registry_spec.rb @@ -14,7 +14,7 @@ describe "Container Registry" do before do login_as(:user) project.team << [@user, :developer] - stub_container_registry(*tags) + stub_container_registry_tags(*tags) allow(Gitlab.config.registry).to receive_messages(registry_settings) allow(Auth::ContainerRegistryAuthenticationService).to receive(:full_access_token).and_return('token') end diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 4074f966299..4e68ac5e63a 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -70,6 +70,20 @@ describe Namespace, models: true do allow(@namespace).to receive(:path).and_return(new_path) expect(@namespace.move_dir).to be_truthy end + + context "when any project has container tags" do + before do + stub_container_registry_config(enabled: true) + stub_container_registry_tags('tag') + + create(:empty_project, namespace: @namespace) + + allow(@namespace).to receive(:path_was).and_return(@namespace.path) + allow(@namespace).to receive(:path).and_return('new_path') + end + + it { expect { @namespace.move_dir }.to raise_error('Namespace cannot be moved, because at least one project has tags in container registry') } + end end describe :rm_dir do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 6de75af08e4..262f4122220 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -634,11 +634,11 @@ describe Project, models: true do # Project#gitlab_shell returns a new instance of Gitlab::Shell on every # call. This makes testing a bit easier. allow(project).to receive(:gitlab_shell).and_return(gitlab_shell) - end - it 'renames a repository' do allow(project).to receive(:previous_changes).and_return('path' => ['foo']) + end + it 'renames a repository' do ns = project.namespace_dir expect(gitlab_shell).to receive(:mv_repository). @@ -663,6 +663,17 @@ describe Project, models: true do project.rename_repo end + + context 'container registry with tags' do + before do + stub_container_registry_config(enabled: true) + stub_container_registry_tags('tag') + end + + subject { project.rename_repo } + + it { expect{subject}.to raise_error(Exception) } + end end describe '#expire_caches_before_rename' do @@ -825,13 +836,13 @@ describe Project, models: true do end context 'with tags' do - before { stub_container_registry('test', 'test2') } + before { stub_container_registry_tags('test', 'test2') } it { is_expected.to be_truthy } end context 'when no tags' do - before { stub_container_registry } + before { stub_container_registry_tags } it { is_expected.to be_falsey } end diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb index a5cb6f382e4..45b78ccf136 100644 --- a/spec/services/projects/destroy_service_spec.rb +++ b/spec/services/projects/destroy_service_spec.rb @@ -28,6 +28,35 @@ describe Projects::DestroyService, services: true do it { expect(Dir.exist?(remove_path)).to be_truthy } end + context 'container registry' do + let(:registry_settings) do + { + enabled: true + } + end + + before do + allow(Gitlab.config.registry).to receive_messages(registry_settings) + stub_container_registry_tags('tag') + end + + context 'tags deletion succeeds' do + it do + expect_any_instance_of(ContainerRegistry::Tag).to receive(:delete).and_return(true) + + destroy_project(project, user, {}) + end + end + + context 'tags deletion fails' do + before { expect_any_instance_of(ContainerRegistry::Tag).to receive(:delete).and_return(false) } + + subject { destroy_project(project, user, {}) } + + it { expect{subject}.to raise_error(Projects::DestroyService::DestroyError) } + end + end + def destroy_project(project, user, params) Projects::DestroyService.new(project, user, params).execute end diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb index 06017317339..d5aa115a074 100644 --- a/spec/services/projects/transfer_service_spec.rb +++ b/spec/services/projects/transfer_service_spec.rb @@ -26,6 +26,17 @@ describe Projects::TransferService, services: true do it { expect(project.namespace).to eq(user.namespace) } end + context 'disallow transfering of project with tags' do + before do + stub_container_registry_config(enabled: true) + stub_container_registry_tags('tag') + end + + subject { transfer_project(project, user, group) } + + it { is_expected.to be_falsey } + end + context 'namespace -> not allowed namespace' do before do @result = transfer_project(project, user, group) diff --git a/spec/support/stub_gitlab_calls.rb b/spec/support/stub_gitlab_calls.rb index 2c31cbe3faf..36e234c2e9c 100644 --- a/spec/support/stub_gitlab_calls.rb +++ b/spec/support/stub_gitlab_calls.rb @@ -25,7 +25,11 @@ module StubGitlabCalls allow_any_instance_of(Project).to receive(:builds_enabled?).and_return(false) end - def stub_container_registry(*tags) + def stub_container_registry_config(registry_settings) + allow(Gitlab.config.registry).to receive_messages(registry_settings) + end + + def stub_container_registry_tags(*tags) allow_any_instance_of(ContainerRegistry::Client).to receive(:repository_tags).and_return( { "tags" => tags } ) |