debian-mirror-gitlab/spec/policies/ci/runner_manager_policy_spec.rb

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

177 lines
5.2 KiB
Ruby
Raw Normal View History

2023-05-27 22:25:52 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-06-20 00:43:36 +05:30
RSpec.describe Ci::RunnerManagerPolicy, feature_category: :runner_fleet do
2023-05-27 22:25:52 +05:30
let_it_be(:owner) { create(:user) }
2023-06-20 00:43:36 +05:30
describe 'ability :read_runner_manager' do
2023-05-27 22:25:52 +05:30
let_it_be(:guest) { create(:user) }
let_it_be(:developer) { create(:user) }
let_it_be(:maintainer) { create(:user) }
let_it_be_with_reload(:group) { create(:group, name: 'top-level', path: 'top-level') }
let_it_be_with_reload(:subgroup) { create(:group, name: 'subgroup', path: 'subgroup', parent: group) }
let_it_be_with_reload(:project) { create(:project, group: subgroup) }
2023-06-20 00:43:36 +05:30
let_it_be(:instance_runner) { create(:ci_runner, :instance, :with_runner_manager) }
let_it_be(:group_runner) { create(:ci_runner, :group, :with_runner_manager, groups: [group]) }
let_it_be(:project_runner) { create(:ci_runner, :project, :with_runner_manager, projects: [project]) }
2023-05-27 22:25:52 +05:30
2023-06-20 00:43:36 +05:30
let(:runner_manager) { runner.runner_managers.first }
2023-05-27 22:25:52 +05:30
2023-06-20 00:43:36 +05:30
subject(:policy) { described_class.new(user, runner_manager) }
2023-05-27 22:25:52 +05:30
before_all do
group.add_guest(guest)
group.add_developer(developer)
group.add_maintainer(maintainer)
group.add_owner(owner)
end
2023-06-20 00:43:36 +05:30
shared_examples 'a policy allowing reading instance runner manager depending on runner sharing' do
2023-05-27 22:25:52 +05:30
context 'with instance runner' do
let(:runner) { instance_runner }
2023-06-20 00:43:36 +05:30
it { expect_allowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
context 'with shared runners disabled on projects' do
before do
project.update!(shared_runners_enabled: false)
end
2023-06-20 00:43:36 +05:30
it { expect_allowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
end
context 'with shared runners disabled for groups and projects' do
before do
group.update!(shared_runners_enabled: false)
project.update!(shared_runners_enabled: false)
end
2023-06-20 00:43:36 +05:30
it { expect_disallowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
end
end
end
2023-06-20 00:43:36 +05:30
shared_examples 'a policy allowing reading group runner manager depending on runner sharing' do
2023-05-27 22:25:52 +05:30
context 'with group runner' do
let(:runner) { group_runner }
2023-06-20 00:43:36 +05:30
it { expect_allowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
context 'with sharing of group runners disabled' do
before do
project.update!(group_runners_enabled: false)
end
2023-06-20 00:43:36 +05:30
it { expect_disallowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
end
end
end
2023-06-20 00:43:36 +05:30
shared_examples 'does not allow reading runners managers on any scope' do
2023-05-27 22:25:52 +05:30
context 'with instance runner' do
let(:runner) { instance_runner }
2023-06-20 00:43:36 +05:30
it { expect_disallowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
context 'with shared runners disabled for groups and projects' do
before do
group.update!(shared_runners_enabled: false)
project.update!(shared_runners_enabled: false)
end
2023-06-20 00:43:36 +05:30
it { expect_disallowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
end
end
context 'with group runner' do
let(:runner) { group_runner }
2023-06-20 00:43:36 +05:30
it { expect_disallowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
context 'with sharing of group runners disabled' do
before do
project.update!(group_runners_enabled: false)
end
2023-06-20 00:43:36 +05:30
it { expect_disallowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
end
end
context 'with project runner' do
let(:runner) { project_runner }
2023-06-20 00:43:36 +05:30
it { expect_disallowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
end
end
context 'without access' do
let_it_be(:user) { create(:user) }
2023-06-20 00:43:36 +05:30
it_behaves_like 'does not allow reading runners managers on any scope'
2023-05-27 22:25:52 +05:30
end
context 'with guest access' do
let(:user) { guest }
2023-06-20 00:43:36 +05:30
it_behaves_like 'does not allow reading runners managers on any scope'
2023-05-27 22:25:52 +05:30
end
context 'with developer access' do
let(:user) { developer }
2023-06-20 00:43:36 +05:30
it_behaves_like 'a policy allowing reading instance runner manager depending on runner sharing'
2023-05-27 22:25:52 +05:30
2023-06-20 00:43:36 +05:30
it_behaves_like 'a policy allowing reading group runner manager depending on runner sharing'
2023-05-27 22:25:52 +05:30
context 'with project runner' do
let(:runner) { project_runner }
2023-06-20 00:43:36 +05:30
it { expect_disallowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
end
end
context 'with maintainer access' do
let(:user) { maintainer }
2023-06-20 00:43:36 +05:30
it_behaves_like 'a policy allowing reading instance runner manager depending on runner sharing'
2023-05-27 22:25:52 +05:30
2023-06-20 00:43:36 +05:30
it_behaves_like 'a policy allowing reading group runner manager depending on runner sharing'
2023-05-27 22:25:52 +05:30
context 'with project runner' do
let(:runner) { project_runner }
2023-06-20 00:43:36 +05:30
it { expect_allowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
end
end
context 'with owner access' do
let(:user) { owner }
2023-06-20 00:43:36 +05:30
it_behaves_like 'a policy allowing reading instance runner manager depending on runner sharing'
2023-05-27 22:25:52 +05:30
context 'with group runner' do
let(:runner) { group_runner }
2023-06-20 00:43:36 +05:30
it { expect_allowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
context 'with sharing of group runners disabled' do
before do
project.update!(group_runners_enabled: false)
end
2023-06-20 00:43:36 +05:30
it { expect_allowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
end
end
context 'with project runner' do
let(:runner) { project_runner }
2023-06-20 00:43:36 +05:30
it { expect_allowed :read_runner_manager }
2023-05-27 22:25:52 +05:30
end
end
end
end