2019-10-25 00:06:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-23 23:19:36 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe ProjectPolicy do
|
2019-04-09 15:38:58 +00:00
|
|
|
include ExternalAuthorizationServiceHelpers
|
2019-03-26 11:31:47 +00:00
|
|
|
include_context 'ProjectPolicy context'
|
2020-09-09 21:08:33 +00:00
|
|
|
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:project) { public_project }
|
|
|
|
|
|
|
|
subject { described_class.new(current_user, project) }
|
2016-09-19 20:21:58 +00:00
|
|
|
|
2017-04-06 21:09:58 +00:00
|
|
|
def expect_allowed(*permissions)
|
|
|
|
permissions.each { |p| is_expected.to be_allowed(p) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_disallowed(*permissions)
|
|
|
|
permissions.each { |p| is_expected.not_to be_allowed(p) }
|
|
|
|
end
|
|
|
|
|
2019-08-25 14:20:17 +00:00
|
|
|
context 'with no project feature' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { owner }
|
2019-08-25 14:20:17 +00:00
|
|
|
|
|
|
|
before do
|
2020-07-29 12:09:45 +00:00
|
|
|
project.project_feature.destroy!
|
2019-08-25 14:20:17 +00:00
|
|
|
project.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be_disallowed(:read_build)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-19 20:21:58 +00:00
|
|
|
it 'does not include the read_issue permission when the issue author is not a member of the private project' do
|
2017-08-02 19:55:11 +00:00
|
|
|
project = create(:project, :private)
|
2017-08-04 17:14:04 +00:00
|
|
|
issue = create(:issue, project: project, author: create(:user))
|
2016-09-19 20:21:58 +00:00
|
|
|
user = issue.author
|
|
|
|
|
2017-04-06 21:09:58 +00:00
|
|
|
expect(project.team.member?(issue.author)).to be false
|
2016-09-19 20:21:58 +00:00
|
|
|
|
2017-04-06 21:09:58 +00:00
|
|
|
expect(Ability).not_to be_allowed(user, :read_issue, project)
|
2016-09-19 20:21:58 +00:00
|
|
|
end
|
2016-09-21 05:09:31 +00:00
|
|
|
|
2020-04-13 15:09:20 +00:00
|
|
|
it_behaves_like 'model with wiki policies' do
|
|
|
|
let(:container) { project }
|
2020-05-06 15:09:42 +00:00
|
|
|
let_it_be(:user) { owner }
|
2019-01-09 15:05:52 +00:00
|
|
|
|
2020-04-13 15:09:20 +00:00
|
|
|
def set_access_level(access_level)
|
|
|
|
project.project_feature.update_attribute(:wiki_access_level, access_level)
|
2019-07-23 22:40:23 +00:00
|
|
|
end
|
2016-11-29 19:30:14 +00:00
|
|
|
end
|
|
|
|
|
2017-06-13 08:25:25 +00:00
|
|
|
context 'issues feature' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { owner }
|
2017-06-13 08:25:25 +00:00
|
|
|
|
|
|
|
context 'when the feature is disabled' do
|
2019-02-11 10:51:53 +00:00
|
|
|
before do
|
2017-06-13 08:25:25 +00:00
|
|
|
project.issues_enabled = false
|
|
|
|
project.save!
|
2019-02-11 10:51:53 +00:00
|
|
|
end
|
2017-06-13 08:25:25 +00:00
|
|
|
|
2019-02-11 10:51:53 +00:00
|
|
|
it 'does not include the issues permissions' do
|
2018-04-02 15:14:20 +00:00
|
|
|
expect_disallowed :read_issue, :read_issue_iid, :create_issue, :update_issue, :admin_issue
|
2017-06-13 08:25:25 +00:00
|
|
|
end
|
|
|
|
|
2019-02-11 10:51:53 +00:00
|
|
|
it 'disables boards and lists permissions' do
|
2019-03-26 11:31:47 +00:00
|
|
|
expect_disallowed :read_board, :create_board, :update_board
|
2019-02-11 10:51:53 +00:00
|
|
|
expect_disallowed :read_list, :create_list, :update_list, :admin_list
|
|
|
|
end
|
2017-06-13 08:25:25 +00:00
|
|
|
|
2019-02-11 10:51:53 +00:00
|
|
|
context 'when external tracker configured' do
|
|
|
|
it 'does not include the issues permissions' do
|
|
|
|
create(:jira_service, project: project)
|
2017-06-13 08:25:25 +00:00
|
|
|
|
2019-02-11 10:51:53 +00:00
|
|
|
expect_disallowed :read_issue, :read_issue_iid, :create_issue, :update_issue, :admin_issue
|
|
|
|
end
|
2017-06-13 08:25:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-06 10:47:52 +00:00
|
|
|
context 'merge requests feature' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { owner }
|
2018-04-06 10:47:52 +00:00
|
|
|
|
|
|
|
it 'disallows all permissions when the feature is disabled' do
|
2020-06-03 18:08:28 +00:00
|
|
|
project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
|
2018-04-06 10:47:52 +00:00
|
|
|
|
2018-04-06 12:18:58 +00:00
|
|
|
mr_permissions = [:create_merge_request_from, :read_merge_request,
|
2018-04-06 10:47:52 +00:00
|
|
|
:update_merge_request, :admin_merge_request,
|
2018-04-06 12:18:58 +00:00
|
|
|
:create_merge_request_in]
|
2018-04-06 10:47:52 +00:00
|
|
|
|
|
|
|
expect_disallowed(*mr_permissions)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-09 19:24:05 +00:00
|
|
|
context 'for a guest in a private project' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { guest }
|
|
|
|
let(:project) { private_project }
|
2019-01-09 19:24:05 +00:00
|
|
|
|
|
|
|
it 'disallows the guest from reading the merge request and merge request iid' do
|
|
|
|
expect_disallowed(:read_merge_request)
|
|
|
|
expect_disallowed(:read_merge_request_iid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-08 00:05:58 +00:00
|
|
|
context 'pipeline feature' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:project) { private_project }
|
2019-11-08 00:05:58 +00:00
|
|
|
|
|
|
|
describe 'for unconfirmed user' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { create(:user, confirmed_at: nil) }
|
2019-11-08 00:05:58 +00:00
|
|
|
|
|
|
|
it 'disallows to modify pipelines' do
|
|
|
|
expect_disallowed(:create_pipeline)
|
|
|
|
expect_disallowed(:update_pipeline)
|
|
|
|
expect_disallowed(:create_pipeline_schedule)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'for confirmed user' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { developer }
|
2019-11-08 00:05:58 +00:00
|
|
|
|
|
|
|
it 'allows modify pipelines' do
|
|
|
|
expect_allowed(:create_pipeline)
|
|
|
|
expect_allowed(:update_pipeline)
|
|
|
|
expect_allowed(:create_pipeline_schedule)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-14 10:34:09 +00:00
|
|
|
context 'builds feature' do
|
2019-01-28 12:12:30 +00:00
|
|
|
context 'when builds are disabled' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { owner }
|
2018-06-14 10:34:09 +00:00
|
|
|
|
2019-01-28 12:12:30 +00:00
|
|
|
before do
|
2020-06-03 18:08:28 +00:00
|
|
|
project.project_feature.update!(builds_access_level: ProjectFeature::DISABLED)
|
2019-01-28 12:12:30 +00:00
|
|
|
end
|
2018-06-14 10:34:09 +00:00
|
|
|
|
2020-05-21 18:08:27 +00:00
|
|
|
it 'disallows all permissions except pipeline when the feature is disabled' do
|
|
|
|
builds_permissions = [
|
|
|
|
:create_build, :read_build, :update_build, :admin_build, :destroy_build,
|
2020-11-02 21:09:10 +00:00
|
|
|
:create_pipeline_schedule, :read_pipeline_schedule_variables, :update_pipeline_schedule, :admin_pipeline_schedule, :destroy_pipeline_schedule,
|
2020-05-21 18:08:27 +00:00
|
|
|
:create_environment, :read_environment, :update_environment, :admin_environment, :destroy_environment,
|
|
|
|
:create_cluster, :read_cluster, :update_cluster, :admin_cluster, :destroy_cluster,
|
|
|
|
:create_deployment, :read_deployment, :update_deployment, :admin_deployment, :destroy_deployment
|
|
|
|
]
|
2020-05-15 21:08:21 +00:00
|
|
|
|
2020-05-21 18:08:27 +00:00
|
|
|
expect_disallowed(*builds_permissions)
|
2019-01-28 12:12:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when builds are disabled only for some users' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { guest }
|
2019-01-28 12:12:30 +00:00
|
|
|
|
|
|
|
before do
|
2020-06-03 18:08:28 +00:00
|
|
|
project.project_feature.update!(builds_access_level: ProjectFeature::PRIVATE)
|
2019-01-28 12:12:30 +00:00
|
|
|
end
|
2018-06-14 10:34:09 +00:00
|
|
|
|
2019-01-28 12:12:30 +00:00
|
|
|
it 'disallows pipeline and commit_status permissions' do
|
|
|
|
builds_permissions = [
|
|
|
|
:create_pipeline, :update_pipeline, :admin_pipeline, :destroy_pipeline,
|
|
|
|
:create_commit_status, :update_commit_status, :admin_commit_status, :destroy_commit_status
|
|
|
|
]
|
|
|
|
|
|
|
|
expect_disallowed(*builds_permissions)
|
|
|
|
end
|
2018-06-14 10:34:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'repository feature' do
|
2020-06-03 18:08:28 +00:00
|
|
|
let(:repository_permissions) do
|
|
|
|
[
|
2020-05-21 18:08:27 +00:00
|
|
|
:create_pipeline, :update_pipeline, :admin_pipeline, :destroy_pipeline,
|
|
|
|
:create_build, :read_build, :update_build, :admin_build, :destroy_build,
|
|
|
|
:create_pipeline_schedule, :read_pipeline_schedule, :update_pipeline_schedule, :admin_pipeline_schedule, :destroy_pipeline_schedule,
|
|
|
|
:create_environment, :read_environment, :update_environment, :admin_environment, :destroy_environment,
|
|
|
|
:create_cluster, :read_cluster, :update_cluster, :admin_cluster,
|
|
|
|
:create_deployment, :read_deployment, :update_deployment, :admin_deployment, :destroy_deployment,
|
2020-06-03 18:08:28 +00:00
|
|
|
:destroy_release, :download_code, :build_download_code
|
2020-05-21 18:08:27 +00:00
|
|
|
]
|
2020-06-03 18:08:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a project member' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { owner }
|
2020-06-03 18:08:28 +00:00
|
|
|
|
|
|
|
context 'when it is disabled' do
|
|
|
|
before do
|
|
|
|
project.project_feature.update!(
|
|
|
|
repository_access_level: ProjectFeature::DISABLED,
|
|
|
|
merge_requests_access_level: ProjectFeature::DISABLED,
|
|
|
|
builds_access_level: ProjectFeature::DISABLED,
|
|
|
|
forking_access_level: ProjectFeature::DISABLED
|
|
|
|
)
|
|
|
|
end
|
2020-05-21 18:08:27 +00:00
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
it 'disallows all permissions' do
|
|
|
|
expect_disallowed(*repository_permissions)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-15 21:09:35 +00:00
|
|
|
context 'when user is non-member' do
|
|
|
|
let(:current_user) { non_member }
|
2020-06-03 18:08:28 +00:00
|
|
|
|
|
|
|
context 'when access level is private' do
|
|
|
|
before do
|
|
|
|
project.project_feature.update!(
|
|
|
|
repository_access_level: ProjectFeature::PRIVATE,
|
|
|
|
merge_requests_access_level: ProjectFeature::PRIVATE,
|
|
|
|
builds_access_level: ProjectFeature::PRIVATE,
|
|
|
|
forking_access_level: ProjectFeature::PRIVATE
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disallows all permissions' do
|
|
|
|
expect_disallowed(*repository_permissions)
|
|
|
|
end
|
|
|
|
end
|
2018-06-14 10:34:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-22 07:13:31 +00:00
|
|
|
it_behaves_like 'project policies as anonymous'
|
|
|
|
it_behaves_like 'project policies as guest'
|
|
|
|
it_behaves_like 'project policies as reporter'
|
|
|
|
it_behaves_like 'project policies as developer'
|
2018-07-11 14:36:08 +00:00
|
|
|
it_behaves_like 'project policies as maintainer'
|
2017-09-22 07:13:31 +00:00
|
|
|
it_behaves_like 'project policies as owner'
|
2020-05-15 15:08:04 +00:00
|
|
|
it_behaves_like 'project policies as admin with admin mode'
|
|
|
|
it_behaves_like 'project policies as admin without admin mode'
|
2018-02-26 12:32:42 +00:00
|
|
|
|
|
|
|
context 'when a public project has merge requests allowing access' do
|
|
|
|
include ProjectForksHelper
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { create(:user) }
|
2018-02-26 12:32:42 +00:00
|
|
|
let(:target_project) { create(:project, :public) }
|
|
|
|
let(:project) { fork_project(target_project) }
|
|
|
|
let!(:merge_request) do
|
|
|
|
create(
|
|
|
|
:merge_request,
|
|
|
|
target_project: target_project,
|
|
|
|
source_project: project,
|
2018-05-23 01:54:57 +00:00
|
|
|
allow_collaboration: true
|
2018-02-26 12:32:42 +00:00
|
|
|
)
|
|
|
|
end
|
2020-08-11 03:11:00 +00:00
|
|
|
|
2018-02-26 12:32:42 +00:00
|
|
|
let(:maintainer_abilities) do
|
2018-05-15 08:18:22 +00:00
|
|
|
%w(create_build create_pipeline)
|
2018-02-26 12:32:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow pushing code' do
|
|
|
|
expect_disallowed(*maintainer_abilities)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows pushing if the user is a member with push access to the target project' do
|
2020-09-15 21:09:35 +00:00
|
|
|
target_project.add_developer(current_user)
|
2018-02-26 12:32:42 +00:00
|
|
|
|
|
|
|
expect_allowed(*maintainer_abilities)
|
|
|
|
end
|
|
|
|
|
2020-05-15 15:08:04 +00:00
|
|
|
it 'disallows abilities to a maintainer if the merge request was closed' do
|
2020-09-15 21:09:35 +00:00
|
|
|
target_project.add_developer(current_user)
|
2018-02-26 12:32:42 +00:00
|
|
|
merge_request.close!
|
|
|
|
|
|
|
|
expect_disallowed(*maintainer_abilities)
|
|
|
|
end
|
|
|
|
end
|
2018-12-04 21:38:15 +00:00
|
|
|
|
|
|
|
it_behaves_like 'clusterable policies' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let_it_be(:clusterable) { create(:project, :repository) }
|
|
|
|
let_it_be(:cluster) do
|
|
|
|
create(:cluster, :provided_by_gcp, :project, projects: [clusterable])
|
2018-12-04 21:38:15 +00:00
|
|
|
end
|
|
|
|
end
|
2019-04-09 15:38:58 +00:00
|
|
|
|
|
|
|
context 'reading a project' do
|
|
|
|
it 'allows access when a user has read access to the repo' do
|
|
|
|
expect(described_class.new(owner, project)).to be_allowed(:read_project)
|
|
|
|
expect(described_class.new(developer, project)).to be_allowed(:read_project)
|
|
|
|
expect(described_class.new(admin, project)).to be_allowed(:read_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'never checks the external service' do
|
|
|
|
expect(::Gitlab::ExternalAuthorization).not_to receive(:access_allowed?)
|
|
|
|
|
|
|
|
expect(described_class.new(owner, project)).to be_allowed(:read_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an external authorization service' do
|
|
|
|
before do
|
|
|
|
enable_external_authorization_service_check
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows access when the external service allows it' do
|
|
|
|
external_service_allow_access(owner, project)
|
|
|
|
external_service_allow_access(developer, project)
|
|
|
|
|
|
|
|
expect(described_class.new(owner, project)).to be_allowed(:read_project)
|
|
|
|
expect(described_class.new(developer, project)).to be_allowed(:read_project)
|
|
|
|
end
|
|
|
|
|
2020-05-15 15:08:04 +00:00
|
|
|
context 'with an admin' do
|
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
|
|
|
it 'does not check the external service and allows access' do
|
|
|
|
expect(::Gitlab::ExternalAuthorization).not_to receive(:access_allowed?)
|
2019-04-09 15:38:58 +00:00
|
|
|
|
2020-05-15 15:08:04 +00:00
|
|
|
expect(described_class.new(admin, project)).to be_allowed(:read_project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode is disabled' do
|
|
|
|
it 'checks the external service and allows access' do
|
|
|
|
external_service_allow_access(admin, project)
|
|
|
|
|
|
|
|
expect(::Gitlab::ExternalAuthorization).to receive(:access_allowed?)
|
|
|
|
|
|
|
|
expect(described_class.new(admin, project)).to be_allowed(:read_project)
|
|
|
|
end
|
|
|
|
end
|
2019-04-09 15:38:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'prevents all but seeing a public project in a list when access is denied' do
|
|
|
|
[developer, owner, build(:user), nil].each do |user|
|
|
|
|
external_service_deny_access(user, project)
|
|
|
|
policy = described_class.new(user, project)
|
|
|
|
|
|
|
|
expect(policy).not_to be_allowed(:read_project)
|
|
|
|
expect(policy).not_to be_allowed(:owner_access)
|
|
|
|
expect(policy).not_to be_allowed(:change_namespace)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'passes the full path to external authorization for logging purposes' do
|
|
|
|
expect(::Gitlab::ExternalAuthorization)
|
|
|
|
.to receive(:access_allowed?).with(owner, 'default_label', project.full_path).and_call_original
|
|
|
|
|
|
|
|
described_class.new(owner, project).allowed?(:read_project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-10-14 15:06:07 +00:00
|
|
|
|
2020-01-20 15:09:18 +00:00
|
|
|
context 'forking a project' do
|
|
|
|
context 'anonymous user' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-01-20 15:09:18 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:fork_project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'project member' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:project) { private_project }
|
2020-01-20 15:09:18 +00:00
|
|
|
|
|
|
|
context 'guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:fork_project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(reporter developer maintainer).each do |role|
|
|
|
|
context role do
|
|
|
|
let(:current_user) { send(role) }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:fork_project) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-14 15:06:07 +00:00
|
|
|
describe 'update_max_artifacts_size' do
|
|
|
|
context 'when no user' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2019-10-14 15:06:07 +00:00
|
|
|
|
|
|
|
it { expect_disallowed(:update_max_artifacts_size) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'admin' do
|
|
|
|
let(:current_user) { admin }
|
|
|
|
|
2020-05-15 15:08:04 +00:00
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
|
|
|
it { expect_allowed(:update_max_artifacts_size) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode is disabled' do
|
|
|
|
it { expect_disallowed(:update_max_artifacts_size) }
|
|
|
|
end
|
2019-10-14 15:06:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
%w(guest reporter developer maintainer owner).each do |role|
|
|
|
|
context role do
|
|
|
|
let(:current_user) { send(role) }
|
|
|
|
|
|
|
|
it { expect_disallowed(:update_max_artifacts_size) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-06 12:10:29 +00:00
|
|
|
|
|
|
|
context 'alert bot' do
|
|
|
|
let(:current_user) { User.alert_bot }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:reporter_access) }
|
|
|
|
|
|
|
|
context 'within a private project' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:project) { private_project }
|
2020-02-06 12:10:29 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:admin_issue) }
|
|
|
|
end
|
|
|
|
end
|
2020-03-25 09:08:11 +00:00
|
|
|
|
2020-06-22 15:09:27 +00:00
|
|
|
context 'support bot' do
|
|
|
|
let(:current_user) { User.support_bot }
|
|
|
|
|
|
|
|
context 'with service desk disabled' do
|
|
|
|
it { expect_allowed(:guest_access) }
|
|
|
|
it { expect_disallowed(:create_note, :read_project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with service desk enabled' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:service_desk_enabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect_allowed(:reporter_access, :create_note, :read_issue) }
|
|
|
|
|
|
|
|
context 'when issues are protected members only' do
|
|
|
|
before do
|
|
|
|
project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect_allowed(:reporter_access, :create_note, :read_issue) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-25 09:08:11 +00:00
|
|
|
describe 'read_prometheus_alerts' do
|
|
|
|
context 'with admin' do
|
|
|
|
let(:current_user) { admin }
|
|
|
|
|
2020-05-15 15:08:04 +00:00
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus_alerts) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode is disabled' do
|
|
|
|
it { is_expected.to be_disallowed(:read_prometheus_alerts) }
|
|
|
|
end
|
2020-03-25 09:08:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with owner' do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus_alerts) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with maintainer' do
|
|
|
|
let(:current_user) { maintainer }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus_alerts) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with developer' do
|
|
|
|
let(:current_user) { developer }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:read_prometheus_alerts) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:read_prometheus_alerts) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:read_prometheus_alerts) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-03-25 09:08:11 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:read_prometheus_alerts) }
|
|
|
|
end
|
|
|
|
end
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
describe 'metrics_dashboard feature' do
|
|
|
|
context 'public project' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:project) { public_project }
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
context 'feature private' do
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:metrics_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus) }
|
|
|
|
it { is_expected.to be_allowed(:read_deployment) }
|
2020-05-11 18:09:55 +00:00
|
|
|
it { is_expected.to be_allowed(:read_metrics_user_starred_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:create_metrics_user_starred_dashboard) }
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'feature enabled' do
|
|
|
|
before do
|
2020-06-03 18:08:28 +00:00
|
|
|
project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED)
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:metrics_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus) }
|
|
|
|
it { is_expected.to be_allowed(:read_deployment) }
|
2020-05-11 18:09:55 +00:00
|
|
|
it { is_expected.to be_allowed(:read_metrics_user_starred_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:create_metrics_user_starred_dashboard) }
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:metrics_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus) }
|
|
|
|
it { is_expected.to be_allowed(:read_deployment) }
|
2020-05-11 18:09:55 +00:00
|
|
|
it { is_expected.to be_allowed(:read_metrics_user_starred_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:create_metrics_user_starred_dashboard) }
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:metrics_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus) }
|
|
|
|
it { is_expected.to be_allowed(:read_deployment) }
|
2020-05-15 21:08:21 +00:00
|
|
|
it { is_expected.to be_disallowed(:read_metrics_user_starred_dashboard) }
|
|
|
|
it { is_expected.to be_disallowed(:create_metrics_user_starred_dashboard) }
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'internal project' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:project) { internal_project }
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
context 'feature private' do
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:metrics_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus) }
|
|
|
|
it { is_expected.to be_allowed(:read_deployment) }
|
2020-05-11 18:09:55 +00:00
|
|
|
it { is_expected.to be_allowed(:read_metrics_user_starred_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:create_metrics_user_starred_dashboard) }
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard)}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'feature enabled' do
|
|
|
|
before do
|
2020-06-03 18:08:28 +00:00
|
|
|
project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED)
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:metrics_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus) }
|
|
|
|
it { is_expected.to be_allowed(:read_deployment) }
|
2020-05-11 18:09:55 +00:00
|
|
|
it { is_expected.to be_allowed(:read_metrics_user_starred_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:create_metrics_user_starred_dashboard) }
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:metrics_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus) }
|
|
|
|
it { is_expected.to be_allowed(:read_deployment) }
|
2020-05-11 18:09:55 +00:00
|
|
|
it { is_expected.to be_allowed(:read_metrics_user_starred_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:create_metrics_user_starred_dashboard) }
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'private project' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:project) { private_project }
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
context 'feature private' do
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:metrics_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus) }
|
|
|
|
it { is_expected.to be_allowed(:read_deployment) }
|
2020-05-11 18:09:55 +00:00
|
|
|
it { is_expected.to be_allowed(:read_metrics_user_starred_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:create_metrics_user_starred_dashboard) }
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'feature enabled' do
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:metrics_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:read_prometheus) }
|
|
|
|
it { is_expected.to be_allowed(:read_deployment) }
|
2020-05-11 18:09:55 +00:00
|
|
|
it { is_expected.to be_allowed(:read_metrics_user_starred_dashboard) }
|
|
|
|
it { is_expected.to be_allowed(:create_metrics_user_starred_dashboard) }
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'feature disabled' do
|
|
|
|
before do
|
2020-06-03 18:08:28 +00:00
|
|
|
project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::DISABLED)
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-04-30 09:09:39 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:metrics_dashboard) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-13 09:08:37 +00:00
|
|
|
|
|
|
|
context 'deploy token access' do
|
|
|
|
let!(:project_deploy_token) do
|
|
|
|
create(:project_deploy_token, project: project, deploy_token: deploy_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(deploy_token, project) }
|
|
|
|
|
|
|
|
context 'a deploy token with read_package_registry scope' do
|
|
|
|
let(:deploy_token) { create(:deploy_token, read_package_registry: true) }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_package) }
|
|
|
|
it { is_expected.to be_allowed(:read_project) }
|
|
|
|
it { is_expected.to be_disallowed(:create_package) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'a deploy token with write_package_registry scope' do
|
|
|
|
let(:deploy_token) { create(:deploy_token, write_package_registry: true) }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:create_package) }
|
2020-11-16 21:09:02 +00:00
|
|
|
it { is_expected.to be_allowed(:read_package) }
|
2020-05-13 09:08:37 +00:00
|
|
|
it { is_expected.to be_allowed(:read_project) }
|
|
|
|
it { is_expected.to be_disallowed(:destroy_package) }
|
|
|
|
end
|
|
|
|
end
|
2020-05-25 15:07:58 +00:00
|
|
|
|
|
|
|
describe 'create_web_ide_terminal' do
|
|
|
|
context 'with admin' do
|
|
|
|
let(:current_user) { admin }
|
|
|
|
|
|
|
|
context 'when admin mode enabled', :enable_admin_mode do
|
|
|
|
it { is_expected.to be_allowed(:create_web_ide_terminal) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode disabled' do
|
|
|
|
it { is_expected.to be_disallowed(:create_web_ide_terminal) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with owner' do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:create_web_ide_terminal) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with maintainer' do
|
|
|
|
let(:current_user) { maintainer }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:create_web_ide_terminal) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with developer' do
|
|
|
|
let(:current_user) { developer }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:create_web_ide_terminal) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:create_web_ide_terminal) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:create_web_ide_terminal) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with non member' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { non_member }
|
2020-05-25 15:07:58 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:create_web_ide_terminal) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-05-25 15:07:58 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:create_web_ide_terminal) }
|
|
|
|
end
|
|
|
|
end
|
2020-06-05 15:08:23 +00:00
|
|
|
|
|
|
|
describe 'read_repository_graphs' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { guest }
|
2020-06-05 15:08:23 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:allowed?).with(:read_repository_graphs).and_call_original
|
|
|
|
allow(subject).to receive(:allowed?).with(:download_code).and_return(can_download_code)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can download_code' do
|
|
|
|
let(:can_download_code) { true }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_repository_graphs) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user cannot download_code' do
|
|
|
|
let(:can_download_code) { false }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:read_repository_graphs) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-19 18:08:39 +00:00
|
|
|
describe 'design permissions' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { guest }
|
2020-06-19 18:08:39 +00:00
|
|
|
|
|
|
|
let(:design_permissions) do
|
|
|
|
%i[read_design_activity read_design]
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when design management is not available' do
|
|
|
|
it { is_expected.not_to be_allowed(*design_permissions) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when design management is available' do
|
|
|
|
include DesignManagementTestHelpers
|
|
|
|
|
|
|
|
before do
|
|
|
|
enable_design_management
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(*design_permissions) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-05 15:08:23 +00:00
|
|
|
describe 'read_build_report_results' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { guest }
|
2020-06-05 15:08:23 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:allowed?).with(:read_build_report_results).and_call_original
|
|
|
|
allow(subject).to receive(:allowed?).with(:read_build).and_return(can_read_build)
|
|
|
|
allow(subject).to receive(:allowed?).with(:read_pipeline).and_return(can_read_pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can read_build and read_pipeline' do
|
|
|
|
let(:can_read_build) { true }
|
|
|
|
let(:can_read_pipeline) { true }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_build_report_results) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can read_build but cannot read_pipeline' do
|
|
|
|
let(:can_read_build) { true }
|
|
|
|
let(:can_read_pipeline) { false }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:read_build_report_results) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user cannot read_build but can read_pipeline' do
|
|
|
|
let(:can_read_build) { false }
|
|
|
|
let(:can_read_pipeline) { true }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:read_build_report_results) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user cannot read_build and cannot read_pipeline' do
|
|
|
|
let(:can_read_build) { false }
|
|
|
|
let(:can_read_pipeline) { false }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:read_build_report_results) }
|
|
|
|
end
|
|
|
|
end
|
2020-07-13 06:09:23 +00:00
|
|
|
|
|
|
|
describe 'read_package' do
|
|
|
|
context 'with admin' do
|
|
|
|
let(:current_user) { admin }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_package) }
|
|
|
|
|
|
|
|
context 'when repository is disabled' do
|
|
|
|
before do
|
2020-07-29 12:09:45 +00:00
|
|
|
project.project_feature.update!(
|
|
|
|
# Disable merge_requests and builds as well, since merge_requests and
|
|
|
|
# builds cannot have higher visibility than repository.
|
|
|
|
merge_requests_access_level: ProjectFeature::DISABLED,
|
|
|
|
builds_access_level: ProjectFeature::DISABLED,
|
|
|
|
repository_access_level: ProjectFeature::DISABLED)
|
2020-07-13 06:09:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:read_package) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with owner' do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_package) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with maintainer' do
|
|
|
|
let(:current_user) { maintainer }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_package) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with developer' do
|
|
|
|
let(:current_user) { developer }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_package) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_package) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_package) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with non member' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { non_member }
|
2020-07-13 06:09:23 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_package) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous' do
|
2020-09-15 21:09:35 +00:00
|
|
|
let(:current_user) { anonymous }
|
2020-07-13 06:09:23 +00:00
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_package) }
|
|
|
|
end
|
|
|
|
end
|
2020-09-17 06:09:32 +00:00
|
|
|
|
|
|
|
describe 'read_feature_flag' do
|
|
|
|
subject { described_class.new(current_user, project) }
|
|
|
|
|
|
|
|
context 'with maintainer' do
|
|
|
|
let(:current_user) { maintainer }
|
|
|
|
|
|
|
|
context 'when repository is available' do
|
|
|
|
it { is_expected.to be_allowed(:read_feature_flag) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository is disabled' do
|
|
|
|
before do
|
|
|
|
project.project_feature.update!(
|
|
|
|
merge_requests_access_level: ProjectFeature::DISABLED,
|
|
|
|
builds_access_level: ProjectFeature::DISABLED,
|
|
|
|
repository_access_level: ProjectFeature::DISABLED
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:read_feature_flag) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with developer' do
|
|
|
|
let(:current_user) { developer }
|
|
|
|
|
|
|
|
context 'when repository is available' do
|
|
|
|
it { is_expected.to be_allowed(:read_feature_flag) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with reporter' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
context 'when repository is available' do
|
|
|
|
it { is_expected.to be_disallowed(:read_feature_flag) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-09-30 18:09:52 +00:00
|
|
|
|
|
|
|
it_behaves_like 'Self-managed Core resource access tokens'
|
2020-11-27 12:09:14 +00:00
|
|
|
|
|
|
|
describe 'operations feature' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let(:guest_operations_permissions) { [:read_environment, :read_deployment] }
|
|
|
|
|
|
|
|
let(:developer_operations_permissions) do
|
|
|
|
guest_operations_permissions + [
|
|
|
|
:read_feature_flag, :read_sentry_issue, :read_alert_management_alert, :read_terraform_state,
|
|
|
|
:metrics_dashboard, :read_pod_logs, :read_prometheus, :create_feature_flag,
|
|
|
|
:create_environment, :create_deployment, :update_feature_flag, :update_environment,
|
|
|
|
:update_sentry_issue, :update_alert_management_alert, :update_deployment,
|
|
|
|
:destroy_feature_flag, :destroy_environment, :admin_feature_flag
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:maintainer_operations_permissions) do
|
|
|
|
developer_operations_permissions + [
|
|
|
|
:read_cluster, :create_cluster, :update_cluster, :admin_environment,
|
|
|
|
:admin_cluster, :admin_terraform_state, :admin_deployment
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
where(:project_visibility, :access_level, :role, :allowed) do
|
|
|
|
:public | ProjectFeature::ENABLED | :maintainer | true
|
|
|
|
:public | ProjectFeature::ENABLED | :developer | true
|
|
|
|
:public | ProjectFeature::ENABLED | :guest | true
|
|
|
|
:public | ProjectFeature::ENABLED | :anonymous | true
|
|
|
|
:public | ProjectFeature::PRIVATE | :maintainer | true
|
|
|
|
:public | ProjectFeature::PRIVATE | :developer | true
|
|
|
|
:public | ProjectFeature::PRIVATE | :guest | true
|
|
|
|
:public | ProjectFeature::PRIVATE | :anonymous | false
|
|
|
|
:public | ProjectFeature::DISABLED | :maintainer | false
|
|
|
|
:public | ProjectFeature::DISABLED | :developer | false
|
|
|
|
:public | ProjectFeature::DISABLED | :guest | false
|
|
|
|
:public | ProjectFeature::DISABLED | :anonymous | false
|
|
|
|
:internal | ProjectFeature::ENABLED | :maintainer | true
|
|
|
|
:internal | ProjectFeature::ENABLED | :developer | true
|
|
|
|
:internal | ProjectFeature::ENABLED | :guest | true
|
|
|
|
:internal | ProjectFeature::ENABLED | :anonymous | false
|
|
|
|
:internal | ProjectFeature::PRIVATE | :maintainer | true
|
|
|
|
:internal | ProjectFeature::PRIVATE | :developer | true
|
|
|
|
:internal | ProjectFeature::PRIVATE | :guest | true
|
|
|
|
:internal | ProjectFeature::PRIVATE | :anonymous | false
|
|
|
|
:internal | ProjectFeature::DISABLED | :maintainer | false
|
|
|
|
:internal | ProjectFeature::DISABLED | :developer | false
|
|
|
|
:internal | ProjectFeature::DISABLED | :guest | false
|
|
|
|
:internal | ProjectFeature::DISABLED | :anonymous | false
|
|
|
|
:private | ProjectFeature::ENABLED | :maintainer | true
|
|
|
|
:private | ProjectFeature::ENABLED | :developer | true
|
|
|
|
:private | ProjectFeature::ENABLED | :guest | false
|
|
|
|
:private | ProjectFeature::ENABLED | :anonymous | false
|
|
|
|
:private | ProjectFeature::PRIVATE | :maintainer | true
|
|
|
|
:private | ProjectFeature::PRIVATE | :developer | true
|
|
|
|
:private | ProjectFeature::PRIVATE | :guest | false
|
|
|
|
:private | ProjectFeature::PRIVATE | :anonymous | false
|
|
|
|
:private | ProjectFeature::DISABLED | :maintainer | false
|
|
|
|
:private | ProjectFeature::DISABLED | :developer | false
|
|
|
|
:private | ProjectFeature::DISABLED | :guest | false
|
|
|
|
:private | ProjectFeature::DISABLED | :anonymous | false
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
let(:current_user) { user_subject(role) }
|
|
|
|
let(:project) { project_subject(project_visibility) }
|
|
|
|
|
|
|
|
it 'allows/disallows the abilities based on the operation feature access level' do
|
|
|
|
project.project_feature.update!(operations_access_level: access_level)
|
|
|
|
|
|
|
|
if allowed
|
|
|
|
expect_allowed(*permissions_abilities(role))
|
|
|
|
else
|
|
|
|
expect_disallowed(*permissions_abilities(role))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_subject(project_type)
|
|
|
|
case project_type
|
|
|
|
when :public
|
|
|
|
public_project
|
|
|
|
when :internal
|
|
|
|
internal_project
|
|
|
|
else
|
|
|
|
private_project
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_subject(role)
|
|
|
|
case role
|
|
|
|
when :maintainer
|
|
|
|
maintainer
|
|
|
|
when :developer
|
|
|
|
developer
|
|
|
|
when :guest
|
|
|
|
guest
|
|
|
|
when :anonymous
|
|
|
|
anonymous
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def permissions_abilities(role)
|
|
|
|
case role
|
|
|
|
when :maintainer
|
|
|
|
maintainer_operations_permissions
|
|
|
|
when :developer
|
|
|
|
developer_operations_permissions
|
|
|
|
else
|
|
|
|
guest_operations_permissions
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-23 23:19:36 +00:00
|
|
|
end
|