debian-mirror-gitlab/spec/services/projects/group_links/update_service_spec.rb

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

77 lines
2.3 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Projects::GroupLinks::UpdateService, '#execute', feature_category: :subgroups do
2020-06-23 00:09:42 +05:30
let_it_be(:user) { create :user }
let_it_be(:group) { create :group }
let_it_be(:project) { create :project }
2021-09-30 23:02:18 +05:30
2020-06-23 00:09:42 +05:30
let!(:link) { create(:project_group_link, project: project, group: group) }
let(:expiry_date) { 1.month.from_now.to_date }
let(:group_link_params) do
{ group_access: Gitlab::Access::GUEST,
expires_at: expiry_date }
end
2022-08-13 15:12:31 +05:30
subject { described_class.new(link, user).execute(group_link_params) }
2020-06-23 00:09:42 +05:30
before do
group.add_developer(user)
end
it 'updates existing link' do
expect(link.group_access).to eq(Gitlab::Access::DEVELOPER)
expect(link.expires_at).to be_nil
subject
link.reload
expect(link.group_access).to eq(Gitlab::Access::GUEST)
expect(link.expires_at).to eq(expiry_date)
end
2021-09-30 23:02:18 +05:30
context 'project authorizations update' do
2021-11-18 22:05:49 +05:30
it 'calls AuthorizedProjectUpdate::ProjectRecalculateWorker to update project authorizations' do
expect(AuthorizedProjectUpdate::ProjectRecalculateWorker)
.to receive(:perform_async).with(link.project.id)
2020-06-23 00:09:42 +05:30
2021-11-18 22:05:49 +05:30
subject
end
2021-09-30 23:02:18 +05:30
2021-11-18 22:05:49 +05:30
it 'calls AuthorizedProjectUpdate::UserRefreshFromReplicaWorker with a delay to update project authorizations' do
2023-04-23 21:23:45 +05:30
stub_feature_flags(do_not_run_safety_net_auth_refresh_jobs: false)
2021-11-18 22:05:49 +05:30
expect(AuthorizedProjectUpdate::UserRefreshFromReplicaWorker).to(
2023-06-20 00:43:36 +05:30
receive(:bulk_perform_in).with(
1.hour,
[[user.id]],
batch_delay: 30.seconds, batch_size: 100
)
2021-11-18 22:05:49 +05:30
)
2021-09-30 23:02:18 +05:30
2021-11-18 22:05:49 +05:30
subject
end
2021-09-30 23:02:18 +05:30
2021-11-18 22:05:49 +05:30
it 'updates project authorizations of users who had access to the project via the group share', :sidekiq_inline do
group.add_maintainer(user)
2021-09-30 23:02:18 +05:30
2021-11-18 22:05:49 +05:30
expect { subject }.to(
change { Ability.allowed?(user, :create_release, project) }
.from(true).to(false))
2021-09-30 23:02:18 +05:30
end
2020-06-23 00:09:42 +05:30
end
context 'with only param not requiring authorization refresh' do
let(:group_link_params) { { expires_at: Date.tomorrow } }
2021-11-18 22:05:49 +05:30
it 'does not perform any project authorizations update using `AuthorizedProjectUpdate::ProjectRecalculateWorker`' do
expect(AuthorizedProjectUpdate::ProjectRecalculateWorker).not_to receive(:perform_async)
2020-06-23 00:09:42 +05:30
2021-11-18 22:05:49 +05:30
subject
2020-06-23 00:09:42 +05:30
end
end
end