debian-mirror-gitlab/spec/policies/clusters/agent_policy_spec.rb

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

47 lines
1.2 KiB
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::AgentPolicy do
2022-10-11 01:57:18 +05:30
let(:cluster_agent) { create(:cluster_agent, name: 'agent' ) }
2021-11-18 22:05:49 +05:30
let(:user) { create(:admin) }
let(:policy) { described_class.new(user, cluster_agent) }
let(:project) { cluster_agent.project }
describe 'rules' do
2023-07-09 08:55:56 +05:30
it { expect(policy).to be_disallowed :read_cluster_agent }
2021-11-18 22:05:49 +05:30
context 'when developer' do
before do
project.add_developer(user)
end
it { expect(policy).to be_disallowed :admin_cluster }
end
context 'when maintainer' do
before do
project.add_maintainer(user)
end
it { expect(policy).to be_allowed :admin_cluster }
end
2023-07-09 08:55:56 +05:30
context 'when agent is ci_access authorized for project members' do
before do
allow(cluster_agent).to receive(:ci_access_authorized_for?).with(user).and_return(true)
end
it { expect(policy).to be_allowed :read_cluster_agent }
end
context 'when agent is user_access authorized for project members' do
before do
allow(cluster_agent).to receive(:user_access_authorized_for?).with(user).and_return(true)
end
it { expect(policy).to be_allowed :read_cluster_agent }
end
2021-11-18 22:05:49 +05:30
end
end