2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.shared_examples 'archived project policies' do
|
|
|
|
let(:feature_write_abilities) do
|
2020-10-24 23:57:45 +05:30
|
|
|
described_class.readonly_features.flat_map do |feature|
|
2019-07-07 11:18:12 +05:30
|
|
|
described_class.create_update_admin_destroy(feature)
|
2020-01-01 13:55:28 +05:30
|
|
|
end + additional_maintainer_permissions
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let(:other_write_abilities) do
|
2020-10-24 23:57:45 +05:30
|
|
|
described_class.readonly_abilities
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project is archived' do
|
|
|
|
before do
|
|
|
|
project.archived = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disables write actions on all relevant project features' do
|
|
|
|
expect_disallowed(*feature_write_abilities)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disables some other important write actions' do
|
|
|
|
expect_disallowed(*other_write_abilities)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not disable other abilities' do
|
|
|
|
expect_allowed(*(regular_abilities - feature_write_abilities - other_write_abilities))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.shared_examples 'project private features with read_all_resources ability' do
|
|
|
|
subject { described_class.new(user, project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.project_feature.update!(
|
|
|
|
repository_access_level: ProjectFeature::PRIVATE,
|
|
|
|
merge_requests_access_level: ProjectFeature::PRIVATE,
|
|
|
|
builds_access_level: ProjectFeature::PRIVATE
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
[:public, :internal, :private].each do |visibility|
|
|
|
|
context "for #{visibility} projects" do
|
|
|
|
let(:project) { create(:project, visibility, namespace: owner.namespace) }
|
|
|
|
|
|
|
|
it 'allows the download_code ability' do
|
|
|
|
expect_allowed(:download_code)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
RSpec.shared_examples 'project policies as anonymous' do
|
|
|
|
context 'abilities for public projects' do
|
|
|
|
context 'when a project has pending invites' do
|
|
|
|
let(:group) { create(:group, :public) }
|
|
|
|
let(:project) { create(:project, :public, namespace: group) }
|
|
|
|
let(:user_permissions) { [:create_merge_request_in, :create_project, :create_issue, :create_note, :upload_file, :award_emoji] }
|
|
|
|
let(:anonymous_permissions) { guest_permissions - user_permissions }
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:current_user) { anonymous }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
create(:group_member, :invited, group: group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not grant owner access' do
|
|
|
|
expect_allowed(*anonymous_permissions)
|
|
|
|
expect_disallowed(*user_permissions)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'archived project policies' do
|
|
|
|
let(:regular_abilities) { anonymous_permissions }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'abilities for non-public projects' do
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:project) { private_project }
|
|
|
|
let(:current_user) { anonymous }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it { is_expected.to be_banned }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-19 02:56:42 +05:30
|
|
|
RSpec.shared_examples 'deploy token does not get confused with user' do
|
|
|
|
before do
|
|
|
|
deploy_token.update!(id: user_id)
|
|
|
|
|
|
|
|
# Project with public builds are available to all
|
|
|
|
project.update!(public_builds: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:deploy_token) { create(:deploy_token) }
|
|
|
|
|
|
|
|
subject { described_class.new(deploy_token, project) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect_disallowed(*guest_permissions)
|
|
|
|
expect_disallowed(*reporter_permissions)
|
|
|
|
expect_disallowed(*team_member_reporter_permissions)
|
|
|
|
expect_disallowed(*developer_permissions)
|
|
|
|
expect_disallowed(*maintainer_permissions)
|
|
|
|
expect_disallowed(*owner_permissions)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
RSpec.shared_examples 'project policies as guest' do
|
|
|
|
context 'abilities for non-public projects' do
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:project) { private_project }
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
let(:reporter_public_build_permissions) do
|
|
|
|
reporter_permissions - [:read_build, :read_pipeline]
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect_allowed(*guest_permissions)
|
|
|
|
expect_disallowed(*reporter_public_build_permissions)
|
|
|
|
expect_disallowed(*team_member_reporter_permissions)
|
|
|
|
expect_disallowed(*developer_permissions)
|
|
|
|
expect_disallowed(*maintainer_permissions)
|
|
|
|
expect_disallowed(*owner_permissions)
|
|
|
|
end
|
|
|
|
|
2020-08-19 02:56:42 +05:30
|
|
|
it_behaves_like 'deploy token does not get confused with user' do
|
|
|
|
let(:user_id) { guest.id }
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it_behaves_like 'archived project policies' do
|
|
|
|
let(:regular_abilities) { guest_permissions }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'public builds enabled' do
|
|
|
|
it do
|
|
|
|
expect_allowed(*guest_permissions)
|
|
|
|
expect_allowed(:read_build, :read_pipeline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when public builds disabled' do
|
|
|
|
before do
|
2020-08-19 02:56:42 +05:30
|
|
|
project.update!(public_builds: false)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect_allowed(*guest_permissions)
|
|
|
|
expect_disallowed(:read_build, :read_pipeline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when builds are disabled' do
|
|
|
|
before do
|
2020-08-19 02:56:42 +05:30
|
|
|
project.project_feature.update!(builds_access_level: ProjectFeature::DISABLED)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect_disallowed(:read_build)
|
|
|
|
expect_allowed(:read_pipeline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'project policies as reporter' do
|
|
|
|
context 'abilities for non-public projects' do
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:project) { private_project }
|
|
|
|
let(:current_user) { reporter }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it do
|
|
|
|
expect_allowed(*guest_permissions)
|
|
|
|
expect_allowed(*reporter_permissions)
|
|
|
|
expect_allowed(*team_member_reporter_permissions)
|
|
|
|
expect_disallowed(*developer_permissions)
|
|
|
|
expect_disallowed(*maintainer_permissions)
|
|
|
|
expect_disallowed(*owner_permissions)
|
|
|
|
end
|
|
|
|
|
2020-08-19 02:56:42 +05:30
|
|
|
it_behaves_like 'deploy token does not get confused with user' do
|
|
|
|
let(:user_id) { reporter.id }
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it_behaves_like 'archived project policies' do
|
|
|
|
let(:regular_abilities) { reporter_permissions }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'project policies as developer' do
|
|
|
|
context 'abilities for non-public projects' do
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:project) { private_project }
|
|
|
|
let(:current_user) { developer }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it do
|
|
|
|
expect_allowed(*guest_permissions)
|
|
|
|
expect_allowed(*reporter_permissions)
|
|
|
|
expect_allowed(*team_member_reporter_permissions)
|
|
|
|
expect_allowed(*developer_permissions)
|
|
|
|
expect_disallowed(*maintainer_permissions)
|
|
|
|
expect_disallowed(*owner_permissions)
|
|
|
|
end
|
|
|
|
|
2020-08-19 02:56:42 +05:30
|
|
|
it_behaves_like 'deploy token does not get confused with user' do
|
|
|
|
let(:user_id) { developer.id }
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it_behaves_like 'archived project policies' do
|
|
|
|
let(:regular_abilities) { developer_permissions }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'project policies as maintainer' do
|
|
|
|
context 'abilities for non-public projects' do
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:project) { private_project }
|
|
|
|
let(:current_user) { maintainer }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it do
|
|
|
|
expect_allowed(*guest_permissions)
|
|
|
|
expect_allowed(*reporter_permissions)
|
|
|
|
expect_allowed(*team_member_reporter_permissions)
|
|
|
|
expect_allowed(*developer_permissions)
|
|
|
|
expect_allowed(*maintainer_permissions)
|
|
|
|
expect_disallowed(*owner_permissions)
|
|
|
|
end
|
|
|
|
|
2020-08-19 02:56:42 +05:30
|
|
|
it_behaves_like 'deploy token does not get confused with user' do
|
|
|
|
let(:user_id) { maintainer.id }
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it_behaves_like 'archived project policies' do
|
|
|
|
let(:regular_abilities) { maintainer_permissions }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'project policies as owner' do
|
|
|
|
context 'abilities for non-public projects' do
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:project) { private_project }
|
|
|
|
let(:current_user) { owner }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it do
|
|
|
|
expect_allowed(*guest_permissions)
|
|
|
|
expect_allowed(*reporter_permissions)
|
|
|
|
expect_allowed(*team_member_reporter_permissions)
|
|
|
|
expect_allowed(*developer_permissions)
|
|
|
|
expect_allowed(*maintainer_permissions)
|
|
|
|
expect_allowed(*owner_permissions)
|
|
|
|
end
|
|
|
|
|
2020-08-19 02:56:42 +05:30
|
|
|
it_behaves_like 'deploy token does not get confused with user' do
|
|
|
|
let(:user_id) { owner.id }
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it_behaves_like 'archived project policies' do
|
|
|
|
let(:regular_abilities) { owner_permissions }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
RSpec.shared_examples 'project policies as admin with admin mode' do
|
|
|
|
context 'abilities for non-public projects', :enable_admin_mode do
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:project) { private_project }
|
|
|
|
let(:current_user) { admin }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it do
|
|
|
|
expect_allowed(*guest_permissions)
|
|
|
|
expect_allowed(*reporter_permissions)
|
|
|
|
expect_disallowed(*team_member_reporter_permissions)
|
|
|
|
expect_allowed(*developer_permissions)
|
|
|
|
expect_allowed(*maintainer_permissions)
|
|
|
|
expect_allowed(*owner_permissions)
|
|
|
|
end
|
|
|
|
|
2020-08-19 02:56:42 +05:30
|
|
|
context 'deploy token does not get confused with user' do
|
|
|
|
before do
|
|
|
|
allow(deploy_token).to receive(:id).and_return(admin.id)
|
|
|
|
|
|
|
|
# Project with public builds are available to all
|
|
|
|
project.update!(public_builds: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:deploy_token) { create(:deploy_token) }
|
|
|
|
|
|
|
|
subject { described_class.new(deploy_token, project) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect_disallowed(*guest_permissions)
|
|
|
|
expect_disallowed(*reporter_permissions)
|
|
|
|
expect_disallowed(*team_member_reporter_permissions)
|
|
|
|
expect_disallowed(*developer_permissions)
|
|
|
|
expect_disallowed(*maintainer_permissions)
|
|
|
|
expect_disallowed(*owner_permissions)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it_behaves_like 'archived project policies' do
|
|
|
|
let(:regular_abilities) { owner_permissions }
|
|
|
|
end
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
context 'abilities for all project visibility', :enable_admin_mode do
|
|
|
|
it_behaves_like 'project private features with read_all_resources ability' do
|
|
|
|
let(:user) { admin }
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
RSpec.shared_examples 'project policies as admin without admin mode' do
|
|
|
|
context 'abilities for non-public projects' do
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:project) { private_project }
|
|
|
|
let(:current_user) { admin }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
it { is_expected.to be_banned }
|
2020-08-19 02:56:42 +05:30
|
|
|
|
|
|
|
context 'deploy token does not get confused with user' do
|
|
|
|
before do
|
|
|
|
allow(deploy_token).to receive(:id).and_return(admin.id)
|
|
|
|
|
|
|
|
# Project with public builds are available to all
|
|
|
|
project.update!(public_builds: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:deploy_token) { create(:deploy_token) }
|
|
|
|
|
|
|
|
subject { described_class.new(deploy_token, project) }
|
|
|
|
|
|
|
|
it { is_expected.to be_banned }
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|