2017-07-03 17:01:05 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Ci::PipelinePolicy, :models do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
|
|
|
|
|
2017-07-03 17:20:44 -04:00
|
|
|
let(:policy) do
|
|
|
|
described_class.new(user, pipeline)
|
2017-07-03 17:01:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'rules' do
|
2017-07-18 10:04:22 -04:00
|
|
|
describe 'rules for protected ref' do
|
2017-08-01 14:51:52 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2017-07-03 17:01:05 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no one can push or merge to the branch' do
|
2017-07-18 10:04:22 -04:00
|
|
|
before do
|
|
|
|
create(:protected_branch, :no_one_can_push,
|
|
|
|
name: pipeline.ref, project: project)
|
|
|
|
end
|
2017-07-03 17:01:05 -04:00
|
|
|
|
|
|
|
it 'does not include ability to update pipeline' do
|
2017-07-03 17:20:44 -04:00
|
|
|
expect(policy).to be_disallowed :update_pipeline
|
2017-07-03 17:01:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when developers can push to the branch' do
|
2017-07-18 10:04:22 -04:00
|
|
|
before do
|
|
|
|
create(:protected_branch, :developers_can_merge,
|
|
|
|
name: pipeline.ref, project: project)
|
|
|
|
end
|
2017-07-03 17:01:05 -04:00
|
|
|
|
|
|
|
it 'includes ability to update pipeline' do
|
2017-07-03 17:20:44 -04:00
|
|
|
expect(policy).to be_allowed :update_pipeline
|
2017-07-03 17:01:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-18 10:04:22 -04:00
|
|
|
context 'when no one can create the tag' do
|
|
|
|
before do
|
|
|
|
create(:protected_tag, :no_one_can_create,
|
|
|
|
name: pipeline.ref, project: project)
|
|
|
|
|
|
|
|
pipeline.update(tag: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include ability to update pipeline' do
|
|
|
|
expect(policy).to be_disallowed :update_pipeline
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no one can create the tag but it is not a tag' do
|
|
|
|
before do
|
|
|
|
create(:protected_tag, :no_one_can_create,
|
|
|
|
name: pipeline.ref, project: project)
|
|
|
|
end
|
2017-07-03 17:01:05 -04:00
|
|
|
|
|
|
|
it 'includes ability to update pipeline' do
|
2017-07-03 17:20:44 -04:00
|
|
|
expect(policy).to be_allowed :update_pipeline
|
2017-07-03 17:01:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-05-15 04:18:22 -04:00
|
|
|
|
|
|
|
context 'when maintainer is allowed to push to pipeline branch' do
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:owner) { user }
|
|
|
|
|
|
|
|
it 'enables update_pipeline if user is maintainer' do
|
|
|
|
allow_any_instance_of(Project).to receive(:empty_repo?).and_return(false)
|
2018-05-22 21:54:57 -04:00
|
|
|
allow_any_instance_of(Project).to receive(:branch_allows_collaboration?).and_return(true)
|
2018-05-15 04:18:22 -04:00
|
|
|
|
|
|
|
expect(policy).to be_allowed :update_pipeline
|
|
|
|
end
|
|
|
|
end
|
2018-11-13 11:17:01 -05:00
|
|
|
|
2019-01-28 07:12:30 -05:00
|
|
|
context 'when user does not have access to internal CI' do
|
|
|
|
let(:project) { create(:project, :builds_disabled, :public) }
|
|
|
|
|
|
|
|
it 'disallows the user from reading the pipeline' do
|
|
|
|
expect(policy).to be_disallowed :read_pipeline
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-13 11:17:01 -05:00
|
|
|
describe 'destroy_pipeline' do
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
|
|
|
|
context 'when user has owner access' do
|
|
|
|
let(:user) { project.owner }
|
|
|
|
|
|
|
|
it 'is enabled' do
|
|
|
|
expect(policy).to be_allowed :destroy_pipeline
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not owner' do
|
|
|
|
it 'is disabled' do
|
|
|
|
expect(policy).not_to be_allowed :destroy_pipeline
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-04-09 10:53:44 -04:00
|
|
|
|
|
|
|
describe 'read_pipeline_variable' do
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
|
|
|
|
context 'when user has owner access' do
|
|
|
|
let(:user) { project.owner }
|
|
|
|
|
|
|
|
it 'is enabled' do
|
|
|
|
expect(policy).to be_allowed :read_pipeline_variable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer and the creator of the pipeline' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline, project: project, user: user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
create(:protected_branch, :developers_can_merge,
|
|
|
|
name: pipeline.ref, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is enabled' do
|
|
|
|
expect(policy).to be_allowed :read_pipeline_variable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer and it is not the creator of the pipeline' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline, project: project, user: project.owner) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
create(:protected_branch, :developers_can_merge,
|
|
|
|
name: pipeline.ref, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is disabled' do
|
|
|
|
expect(policy).to be_disallowed :read_pipeline_variable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not owner nor developer' do
|
|
|
|
it 'is disabled' do
|
|
|
|
expect(policy).not_to be_allowed :read_pipeline_variable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-07-03 17:01:05 -04:00
|
|
|
end
|
|
|
|
end
|