2019-10-24 20:06:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-05 08:29:22 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe Clusters::ClusterPolicy, :models do
|
2017-10-30 11:29:48 -04:00
|
|
|
let(:cluster) { create(:cluster, :project) }
|
|
|
|
let(:project) { cluster.project }
|
2017-10-05 08:29:22 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:policy) { described_class.new(user, cluster) }
|
|
|
|
|
|
|
|
describe 'rules' do
|
|
|
|
context 'when developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(policy).to be_disallowed :update_cluster }
|
|
|
|
it { expect(policy).to be_disallowed :admin_cluster }
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when maintainer' do
|
2017-10-05 08:29:22 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-10-05 08:29:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(policy).to be_allowed :update_cluster }
|
|
|
|
it { expect(policy).to be_allowed :admin_cluster }
|
|
|
|
end
|
2018-10-14 20:42:02 -04:00
|
|
|
|
|
|
|
context 'group cluster' do
|
|
|
|
let(:cluster) { create(:cluster, :group) }
|
|
|
|
let(:group) { cluster.group }
|
|
|
|
let(:project) { create(:project, namespace: group) }
|
|
|
|
|
|
|
|
context 'when group developer' do
|
|
|
|
before do
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(policy).to be_disallowed :update_cluster }
|
|
|
|
it { expect(policy).to be_disallowed :admin_cluster }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when group maintainer' do
|
|
|
|
before do
|
|
|
|
group.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(policy).to be_allowed :update_cluster }
|
|
|
|
it { expect(policy).to be_allowed :admin_cluster }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project maintainer' do
|
|
|
|
before do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(policy).to be_disallowed :update_cluster }
|
|
|
|
it { expect(policy).to be_disallowed :admin_cluster }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(policy).to be_disallowed :update_cluster }
|
|
|
|
it { expect(policy).to be_disallowed :admin_cluster }
|
|
|
|
end
|
|
|
|
end
|
2019-04-09 22:13:43 -04:00
|
|
|
|
|
|
|
context 'instance cluster' do
|
|
|
|
let(:cluster) { create(:cluster, :instance) }
|
|
|
|
|
|
|
|
context 'when user' do
|
|
|
|
it { expect(policy).to be_disallowed :update_cluster }
|
|
|
|
it { expect(policy).to be_disallowed :admin_cluster }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin' do
|
|
|
|
let(:user) { create(:admin) }
|
|
|
|
|
2020-05-15 11:08:04 -04:00
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
|
|
|
it { expect(policy).to be_allowed :update_cluster }
|
|
|
|
it { expect(policy).to be_allowed :admin_cluster }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode is disabled' do
|
|
|
|
it { expect(policy).to be_disallowed :update_cluster }
|
|
|
|
it { expect(policy).to be_disallowed :admin_cluster }
|
|
|
|
end
|
2019-04-09 22:13:43 -04:00
|
|
|
end
|
|
|
|
end
|
2017-10-05 08:29:22 -04:00
|
|
|
end
|
|
|
|
end
|