debian-mirror-gitlab/spec/services/groups/group_links/destroy_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

118 lines
4.1 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Groups::GroupLinks::DestroyService, '#execute' do
2022-07-16 23:28:13 +05:30
let_it_be(:user) { create(:user) }
2019-12-26 22:10:19 +05:30
let_it_be(:group) { create(:group, :private) }
let_it_be(:shared_group) { create(:group, :private) }
let_it_be(:project) { create(:project, group: shared_group) }
2020-06-23 00:09:42 +05:30
let_it_be(:owner) { create(:user) }
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
subject { described_class.new(shared_group, owner) }
2019-12-26 22:10:19 +05:30
2022-07-16 23:28:13 +05:30
context 'when authorizing by user' do
before do
group.add_developer(owner)
shared_group.add_owner(owner)
end
context 'single link' do
let!(:link) { create(:group_group_link, shared_group: shared_group, shared_with_group: group) }
2019-12-26 22:10:19 +05:30
2022-07-16 23:28:13 +05:30
it 'destroys the link' do
expect { subject.execute(link) }.to change { shared_group.shared_with_group_links.count }.from(1).to(0)
end
2022-08-13 15:12:31 +05:30
context 'with skip_group_share_unlink_auth_refresh feature flag disabled' do
before do
stub_feature_flags(skip_group_share_unlink_auth_refresh: false)
end
2022-07-16 23:28:13 +05:30
2022-08-13 15:12:31 +05:30
it 'revokes project authorization', :sidekiq_inline do
group.add_developer(user)
expect { subject.execute(link) }.to(
change { Ability.allowed?(user, :read_project, project) }.from(true).to(false))
end
end
context 'with skip_group_share_unlink_auth_refresh feature flag enabled' do
before do
stub_feature_flags(skip_group_share_unlink_auth_refresh: true)
end
it 'maintains project authorization', :sidekiq_inline do
group.add_developer(user)
expect(Ability.allowed?(user, :read_project, project)).to be_truthy
end
2022-07-16 23:28:13 +05:30
end
2019-12-26 22:10:19 +05:30
end
2022-07-16 23:28:13 +05:30
context 'multiple links' do
let_it_be(:another_group) { create(:group, :private) }
let_it_be(:another_shared_group) { create(:group, :private) }
let!(:links) do
[
create(:group_group_link, shared_group: shared_group, shared_with_group: group),
create(:group_group_link, shared_group: shared_group, shared_with_group: another_group),
create(:group_group_link, shared_group: another_shared_group, shared_with_group: group),
create(:group_group_link, shared_group: another_shared_group, shared_with_group: another_group)
]
end
2019-12-26 22:10:19 +05:30
2022-08-13 15:12:31 +05:30
context 'with skip_group_share_unlink_auth_refresh feature flag disabled' do
before do
stub_feature_flags(skip_group_share_unlink_auth_refresh: false)
end
it 'updates project authorization once per group' do
expect(GroupGroupLink).to receive(:delete).and_call_original
expect(group).to receive(:refresh_members_authorized_projects).with(direct_members_only: true, blocking: false).once
expect(another_group).to receive(:refresh_members_authorized_projects).with(direct_members_only: true, blocking: false).once
subject.execute(links)
end
end
context 'with skip_group_share_unlink_auth_refresh feature flag enabled' do
before do
stub_feature_flags(skip_group_share_unlink_auth_refresh: true)
end
it 'does not update project authorization once per group' do
expect(GroupGroupLink).to receive(:delete).and_call_original
expect(group).not_to receive(:refresh_members_authorized_projects)
expect(another_group).not_to receive(:refresh_members_authorized_projects)
2022-07-16 23:28:13 +05:30
2022-08-13 15:12:31 +05:30
subject.execute(links)
end
2022-07-16 23:28:13 +05:30
end
2019-12-26 22:10:19 +05:30
end
end
2022-07-16 23:28:13 +05:30
context 'when skipping authorization' do
let!(:link) { create(:group_group_link, shared_group: shared_group, shared_with_group: group) }
context 'with provided group and owner' do
it 'destroys the link' do
expect do
subject.execute(link, skip_authorization: true)
end.to change { shared_group.shared_with_group_links.count }.from(1).to(0)
end
2019-12-26 22:10:19 +05:30
end
2022-07-16 23:28:13 +05:30
context 'without providing group or owner' do
subject { described_class.new(nil, nil) }
2019-12-26 22:10:19 +05:30
2022-07-16 23:28:13 +05:30
it 'destroys the link' do
expect do
subject.execute(link, skip_authorization: true)
end.to change { shared_group.shared_with_group_links.count }.from(1).to(0)
end
2019-12-26 22:10:19 +05:30
end
end
end