diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-25 19:30:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-25 19:30:40 +0300 |
commit | b485c8c3723dc5aaba15ab9fa258010d1ec66d61 (patch) | |
tree | 36cd2260b2f31bc77ad313b644e5784160ce9104 /spec/services | |
parent | 479d579719c36f1b8706165c20f4525bc32bb451 (diff) |
Add latest changes from gitlab-org/security/gitlab@14-8-stable-ee
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/members/create_service_spec.rb | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/spec/services/members/create_service_spec.rb b/spec/services/members/create_service_spec.rb index 4d9e69719b4..4396a0d3ec3 100644 --- a/spec/services/members/create_service_spec.rb +++ b/spec/services/members/create_service_spec.rb @@ -11,19 +11,37 @@ RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_ let(:additional_params) { { invite_source: '_invite_source_' } } let(:params) { { user_ids: user_ids, access_level: access_level }.merge(additional_params) } + let(:current_user) { user } - subject(:execute_service) { described_class.new(user, params.merge({ source: source })).execute } + subject(:execute_service) { described_class.new(current_user, params.merge({ source: source })).execute } before do - if source.is_a?(Project) + case source + when Project source.add_maintainer(user) OnboardingProgress.onboard(source.namespace) - else + when Group source.add_owner(user) OnboardingProgress.onboard(source) end end + context 'when the current user does not have permission to create members' do + let(:current_user) { create(:user) } + + it 'raises a Gitlab::Access::AccessDeniedError' do + expect { execute_service }.to raise_error(Gitlab::Access::AccessDeniedError) + end + end + + context 'when passing an invalid source' do + let_it_be(:source) { Object.new } + + it 'raises a RuntimeError' do + expect { execute_service }.to raise_error(RuntimeError, 'Unknown source type: Object!') + end + end + context 'when passing valid parameters' do it 'adds a user to members' do expect(execute_service[:status]).to eq(:success) |