2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe BasePolicy do
|
2019-05-18 00:54:41 +05:30
|
|
|
include ExternalAuthorizationServiceHelpers
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '.class_for' do
|
|
|
|
it 'detects policy class based on the subject ancestors' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(DeclarativePolicy.class_for(GenericCommitStatus.new)).to eq(CommitStatusPolicy)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'detects policy class for a presented subject' do
|
|
|
|
presentee = Ci::BuildPresenter.new(Ci::Build.new)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(DeclarativePolicy.class_for(presentee)).to eq(Ci::BuildPolicy)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses GlobalPolicy when :global is given' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(DeclarativePolicy.class_for(:global)).to eq(GlobalPolicy)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2019-05-18 00:54:41 +05:30
|
|
|
|
|
|
|
describe 'read cross project' do
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject { described_class.new(current_user, [user]) }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_cross_project) }
|
|
|
|
|
|
|
|
context 'when an external authorization service is enabled' do
|
|
|
|
before do
|
|
|
|
enable_external_authorization_service_check
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.not_to be_allowed(:read_cross_project) }
|
|
|
|
|
|
|
|
it 'allows admins' do
|
|
|
|
expect(described_class.new(build(:admin), nil)).to be_allowed(:read_cross_project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|