diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/services/groups | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/services/groups')
14 files changed, 252 insertions, 13 deletions
diff --git a/spec/services/groups/auto_devops_service_spec.rb b/spec/services/groups/auto_devops_service_spec.rb index 63fbdc70c1b..3d89ee96823 100644 --- a/spec/services/groups/auto_devops_service_spec.rb +++ b/spec/services/groups/auto_devops_service_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Groups::AutoDevopsService, '#execute' do +RSpec.describe Groups::AutoDevopsService, '#execute' do let_it_be(:group) { create(:group) } let_it_be(:user) { create(:user) } let(:group_params) { { auto_devops_enabled: '0' } } diff --git a/spec/services/groups/create_service_spec.rb b/spec/services/groups/create_service_spec.rb index c0e876cce33..fc877f45a39 100644 --- a/spec/services/groups/create_service_spec.rb +++ b/spec/services/groups/create_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::CreateService, '#execute' do +RSpec.describe Groups::CreateService, '#execute' do let!(:user) { create(:user) } let!(:group_params) { { path: "group_path", visibility_level: Gitlab::VisibilityLevel::PUBLIC } } @@ -129,4 +129,13 @@ describe Groups::CreateService, '#execute' do expect { subject }.to change { ChatTeam.count }.from(0).to(1) end end + + describe 'creating a setting record' do + let(:service) { described_class.new(user, group_params) } + + it 'create the settings record connected to the group' do + group = subject + expect(group.namespace_settings).to be_persisted + end + end end diff --git a/spec/services/groups/deploy_tokens/create_service_spec.rb b/spec/services/groups/deploy_tokens/create_service_spec.rb index 20c609bc828..0c28075f998 100644 --- a/spec/services/groups/deploy_tokens/create_service_spec.rb +++ b/spec/services/groups/deploy_tokens/create_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::DeployTokens::CreateService do +RSpec.describe Groups::DeployTokens::CreateService do it_behaves_like 'a deploy token creation service' do let(:entity) { create(:group) } let(:deploy_token_class) { GroupDeployToken } diff --git a/spec/services/groups/deploy_tokens/destroy_service_spec.rb b/spec/services/groups/deploy_tokens/destroy_service_spec.rb index d4ef5963558..28e60b12993 100644 --- a/spec/services/groups/deploy_tokens/destroy_service_spec.rb +++ b/spec/services/groups/deploy_tokens/destroy_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::DeployTokens::DestroyService do +RSpec.describe Groups::DeployTokens::DestroyService do it_behaves_like 'a deploy token deletion service' do let_it_be(:entity) { create(:group) } let_it_be(:deploy_token_class) { GroupDeployToken } diff --git a/spec/services/groups/destroy_service_spec.rb b/spec/services/groups/destroy_service_spec.rb index bf639153b99..31afdba8192 100644 --- a/spec/services/groups/destroy_service_spec.rb +++ b/spec/services/groups/destroy_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::DestroyService do +RSpec.describe Groups::DestroyService do include DatabaseConnectionHelpers let!(:user) { create(:user) } diff --git a/spec/services/groups/group_links/create_service_spec.rb b/spec/services/groups/group_links/create_service_spec.rb index 36faa69577e..bca03863d1e 100644 --- a/spec/services/groups/group_links/create_service_spec.rb +++ b/spec/services/groups/group_links/create_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::GroupLinks::CreateService, '#execute' do +RSpec.describe Groups::GroupLinks::CreateService, '#execute' do let(:parent_group_user) { create(:user) } let(:group_user) { create(:user) } let(:child_group_user) { create(:user) } diff --git a/spec/services/groups/group_links/destroy_service_spec.rb b/spec/services/groups/group_links/destroy_service_spec.rb index 8989f024262..22fe8a1d58b 100644 --- a/spec/services/groups/group_links/destroy_service_spec.rb +++ b/spec/services/groups/group_links/destroy_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::GroupLinks::DestroyService, '#execute' do +RSpec.describe Groups::GroupLinks::DestroyService, '#execute' do let(:user) { create(:user) } let_it_be(:group) { create(:group, :private) } diff --git a/spec/services/groups/group_links/update_service_spec.rb b/spec/services/groups/group_links/update_service_spec.rb index 446364c9799..e4ff83d7926 100644 --- a/spec/services/groups/group_links/update_service_spec.rb +++ b/spec/services/groups/group_links/update_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::GroupLinks::UpdateService, '#execute' do +RSpec.describe Groups::GroupLinks::UpdateService, '#execute' do let(:user) { create(:user) } let_it_be(:group) { create(:group, :private) } diff --git a/spec/services/groups/import_export/export_service_spec.rb b/spec/services/groups/import_export/export_service_spec.rb index ea49b26cc7c..690bcb94556 100644 --- a/spec/services/groups/import_export/export_service_spec.rb +++ b/spec/services/groups/import_export/export_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::ImportExport::ExportService do +RSpec.describe Groups::ImportExport::ExportService do describe '#async_execute' do let(:user) { create(:user) } let(:group) { create(:group) } diff --git a/spec/services/groups/import_export/import_service_spec.rb b/spec/services/groups/import_export/import_service_spec.rb index 1f7eaccbdbd..4aac602a6da 100644 --- a/spec/services/groups/import_export/import_service_spec.rb +++ b/spec/services/groups/import_export/import_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::ImportExport::ImportService do +RSpec.describe Groups::ImportExport::ImportService do describe '#async_execute' do let_it_be(:user) { create(:user) } let_it_be(:group) { create(:group) } diff --git a/spec/services/groups/nested_create_service_spec.rb b/spec/services/groups/nested_create_service_spec.rb index b30392c1b12..a43c1d8d9c3 100644 --- a/spec/services/groups/nested_create_service_spec.rb +++ b/spec/services/groups/nested_create_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::NestedCreateService do +RSpec.describe Groups::NestedCreateService do let(:user) { create(:user) } subject(:service) { described_class.new(user, params) } diff --git a/spec/services/groups/transfer_service_spec.rb b/spec/services/groups/transfer_service_spec.rb index d7f6bececfe..fa254bba6a9 100644 --- a/spec/services/groups/transfer_service_spec.rb +++ b/spec/services/groups/transfer_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::TransferService do +RSpec.describe Groups::TransferService do let(:user) { create(:user) } let(:new_parent_group) { create(:group, :public) } let!(:group_member) { create(:group_member, :owner, group: group, user: user) } diff --git a/spec/services/groups/update_service_spec.rb b/spec/services/groups/update_service_spec.rb index b17d78505d1..25c79d9e600 100644 --- a/spec/services/groups/update_service_spec.rb +++ b/spec/services/groups/update_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Groups::UpdateService do +RSpec.describe Groups::UpdateService do let!(:user) { create(:user) } let!(:private_group) { create(:group, :private) } let!(:internal_group) { create(:group, :internal) } diff --git a/spec/services/groups/update_shared_runners_service_spec.rb b/spec/services/groups/update_shared_runners_service_spec.rb new file mode 100644 index 00000000000..9fd8477a455 --- /dev/null +++ b/spec/services/groups/update_shared_runners_service_spec.rb @@ -0,0 +1,230 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Groups::UpdateSharedRunnersService do + let(:user) { create(:user) } + let(:group) { create(:group) } + let(:params) { {} } + + describe '#execute' do + subject { described_class.new(group, user, params).execute } + + context 'when current_user is not the group owner' do + let_it_be(:group) { create(:group) } + + let(:params) { { shared_runners_enabled: '0' } } + + before do + group.add_maintainer(user) + end + + it 'results error and does not call any method' do + expect(group).not_to receive(:enable_shared_runners!) + expect(group).not_to receive(:disable_shared_runners!) + expect(group).not_to receive(:allow_descendants_override_disabled_shared_runners!) + expect(group).not_to receive(:disallow_descendants_override_disabled_shared_runners!) + + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq('Operation not allowed') + expect(subject[:http_status]).to eq(403) + end + end + + context 'when current_user is the group owner' do + before do + group.add_owner(user) + end + + context 'enable shared Runners' do + where(:desired_params) do + ['1', true] + end + + with_them do + let(:params) { { shared_runners_enabled: desired_params } } + + context 'group that its ancestors have shared runners disabled' do + let_it_be(:parent) { create(:group, :shared_runners_disabled) } + let_it_be(:group) { create(:group, :shared_runners_disabled, parent: parent) } + + it 'results error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq('Shared Runners disabled for the parent group') + end + end + + context 'root group with shared runners disabled' do + let_it_be(:group) { create(:group, :shared_runners_disabled) } + + it 'receives correct method and succeeds' do + expect(group).to receive(:enable_shared_runners!) + expect(group).not_to receive(:disable_shared_runners!) + expect(group).not_to receive(:allow_descendants_override_disabled_shared_runners!) + expect(group).not_to receive(:disallow_descendants_override_disabled_shared_runners!) + + expect(subject[:status]).to eq(:success) + end + end + end + end + + context 'disable shared Runners' do + let_it_be(:group) { create(:group) } + + where(:desired_params) do + ['0', false] + end + + with_them do + let(:params) { { shared_runners_enabled: desired_params } } + + it 'receives correct method and succeeds' do + expect(group).to receive(:disable_shared_runners!) + expect(group).not_to receive(:enable_shared_runners!) + expect(group).not_to receive(:allow_descendants_override_disabled_shared_runners!) + expect(group).not_to receive(:disallow_descendants_override_disabled_shared_runners!) + + expect(subject[:status]).to eq(:success) + end + end + end + + context 'allow descendants to override' do + where(:desired_params) do + ['1', true] + end + + with_them do + let(:params) { { allow_descendants_override_disabled_shared_runners: desired_params } } + + context 'top level group' do + let_it_be(:group) { create(:group, :shared_runners_disabled) } + + it 'receives correct method and succeeds' do + expect(group).to receive(:allow_descendants_override_disabled_shared_runners!) + expect(group).not_to receive(:disallow_descendants_override_disabled_shared_runners!) + expect(group).not_to receive(:enable_shared_runners!) + expect(group).not_to receive(:disable_shared_runners!) + + expect(subject[:status]).to eq(:success) + end + end + + context 'when parent does not allow' do + let_it_be(:parent) { create(:group, :shared_runners_disabled, allow_descendants_override_disabled_shared_runners: false ) } + let_it_be(:group) { create(:group, :shared_runners_disabled, allow_descendants_override_disabled_shared_runners: false, parent: parent) } + + it 'results error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq('Group level shared Runners not allowed') + end + end + end + end + + context 'disallow descendants to override' do + where(:desired_params) do + ['0', false] + end + + with_them do + let(:params) { { allow_descendants_override_disabled_shared_runners: desired_params } } + + context 'top level group' do + let_it_be(:group) { create(:group, :shared_runners_disabled, :allow_descendants_override_disabled_shared_runners ) } + + it 'receives correct method and succeeds' do + expect(group).to receive(:disallow_descendants_override_disabled_shared_runners!) + expect(group).not_to receive(:allow_descendants_override_disabled_shared_runners!) + expect(group).not_to receive(:enable_shared_runners!) + expect(group).not_to receive(:disable_shared_runners!) + + expect(subject[:status]).to eq(:success) + end + end + + context 'top level group that has shared Runners enabled' do + let_it_be(:group) { create(:group, shared_runners_enabled: true) } + + it 'results error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq('Shared Runners enabled') + end + end + end + end + + context 'both params are present' do + context 'shared_runners_enabled: 1 and allow_descendants_override_disabled_shared_runners' do + let_it_be(:group) { create(:group, :shared_runners_disabled) } + let_it_be(:sub_group) { create(:group, :shared_runners_disabled, parent: group) } + let_it_be(:project) { create(:project, shared_runners_enabled: false, group: sub_group) } + + where(:allow_descendants_override) do + ['1', true, '0', false] + end + + with_them do + let(:params) { { shared_runners_enabled: '1', allow_descendants_override_disabled_shared_runners: allow_descendants_override } } + + it 'results in an error because shared Runners are enabled' do + expect { subject } + .to not_change { group.reload.shared_runners_enabled } + .and not_change { sub_group.reload.shared_runners_enabled } + .and not_change { project.reload.shared_runners_enabled } + .and not_change { group.reload.allow_descendants_override_disabled_shared_runners } + .and not_change { sub_group.reload.allow_descendants_override_disabled_shared_runners } + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq('Cannot set shared_runners_enabled to true and allow_descendants_override_disabled_shared_runners') + end + end + end + + context 'shared_runners_enabled: 0 and allow_descendants_override_disabled_shared_runners: 0' do + let_it_be(:group) { create(:group, :allow_descendants_override_disabled_shared_runners) } + let_it_be(:sub_group) { create(:group, :shared_runners_disabled, :allow_descendants_override_disabled_shared_runners, parent: group) } + let_it_be(:sub_group_2) { create(:group, parent: group) } + let_it_be(:project) { create(:project, group: group, shared_runners_enabled: true) } + let_it_be(:project_2) { create(:project, group: sub_group_2, shared_runners_enabled: true) } + + let(:params) { { shared_runners_enabled: '0', allow_descendants_override_disabled_shared_runners: '0' } } + + it 'disables shared Runners and disable allow_descendants_override_disabled_shared_runners' do + expect { subject } + .to change { group.reload.shared_runners_enabled }.from(true).to(false) + .and change { group.reload.allow_descendants_override_disabled_shared_runners }.from(true).to(false) + .and not_change { sub_group.reload.shared_runners_enabled } + .and change { sub_group.reload.allow_descendants_override_disabled_shared_runners }.from(true).to(false) + .and change { sub_group_2.reload.shared_runners_enabled }.from(true).to(false) + .and not_change { sub_group_2.reload.allow_descendants_override_disabled_shared_runners } + .and change { project.reload.shared_runners_enabled }.from(true).to(false) + .and change { project_2.reload.shared_runners_enabled }.from(true).to(false) + end + end + + context 'shared_runners_enabled: 0 and allow_descendants_override_disabled_shared_runners: 1' do + let_it_be(:group) { create(:group) } + let_it_be(:sub_group) { create(:group, :shared_runners_disabled, parent: group) } + let_it_be(:sub_group_2) { create(:group, parent: group) } + let_it_be(:project) { create(:project, group: group, shared_runners_enabled: true) } + let_it_be(:project_2) { create(:project, group: sub_group_2, shared_runners_enabled: true) } + + let(:params) { { shared_runners_enabled: '0', allow_descendants_override_disabled_shared_runners: '1' } } + + it 'disables shared Runners and enable allow_descendants_override_disabled_shared_runners only for itself' do + expect { subject } + .to change { group.reload.shared_runners_enabled }.from(true).to(false) + .and change { group.reload.allow_descendants_override_disabled_shared_runners }.from(false).to(true) + .and not_change { sub_group.reload.shared_runners_enabled } + .and not_change { sub_group.reload.allow_descendants_override_disabled_shared_runners } + .and change { sub_group_2.reload.shared_runners_enabled }.from(true).to(false) + .and not_change { sub_group_2.reload.allow_descendants_override_disabled_shared_runners } + .and change { project.reload.shared_runners_enabled }.from(true).to(false) + .and change { project_2.reload.shared_runners_enabled }.from(true).to(false) + end + end + end + end + end +end |