Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/policies/project_policy_spec.rb')
-rw-r--r--spec/policies/project_policy_spec.rb139
1 files changed, 126 insertions, 13 deletions
diff --git a/spec/policies/project_policy_spec.rb b/spec/policies/project_policy_spec.rb
index 7b3d1abadc1..d363a822d18 100644
--- a/spec/policies/project_policy_spec.rb
+++ b/spec/policies/project_policy_spec.rb
@@ -1080,25 +1080,117 @@ RSpec.describe ProjectPolicy do
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) }
+ context 'private project' do
+ let(:project) { private_project }
- it { is_expected.to be_allowed(:read_package) }
- it { is_expected.to be_allowed(:read_project) }
- it { is_expected.to be_disallowed(:create_package) }
+ context 'a deploy token with read_registry scope' do
+ let(:deploy_token) { create(:deploy_token, read_registry: true, write_registry: false) }
- it_behaves_like 'package access with repository disabled'
+ it { is_expected.to be_allowed(:read_container_image) }
+ it { is_expected.to be_disallowed(:create_container_image) }
+
+ context 'with registry disabled' do
+ include_context 'registry disabled via project features'
+
+ it { is_expected.to be_disallowed(:read_container_image) }
+ it { is_expected.to be_disallowed(:create_container_image) }
+ end
+ end
+
+ context 'a deploy token with write_registry scope' do
+ let(:deploy_token) { create(:deploy_token, read_registry: false, write_registry: true) }
+
+ it { is_expected.to be_disallowed(:read_container_image) }
+ it { is_expected.to be_allowed(:create_container_image) }
+
+ context 'with registry disabled' do
+ include_context 'registry disabled via project features'
+
+ it { is_expected.to be_disallowed(:read_container_image) }
+ it { is_expected.to be_disallowed(:create_container_image) }
+ end
+ end
+
+ context 'a deploy token with no registry scope' do
+ let(:deploy_token) { create(:deploy_token, read_registry: false, write_registry: false) }
+
+ it { is_expected.to be_disallowed(:read_container_image) }
+ it { is_expected.to be_disallowed(:create_container_image) }
+ end
+
+ context 'a deploy token with read_package_registry scope' do
+ let(:deploy_token) { create(:deploy_token, read_repository: false, read_registry: false, read_package_registry: true) }
+
+ it { is_expected.to be_allowed(:read_project) }
+ it { is_expected.to be_allowed(:read_package) }
+ it { is_expected.to be_disallowed(:create_package) }
+
+ it_behaves_like 'package access with repository disabled'
+ end
+
+ context 'a deploy token with write_package_registry scope' do
+ let(:deploy_token) { create(:deploy_token, read_repository: false, read_registry: false, write_package_registry: true) }
+
+ it { is_expected.to be_allowed(:create_package) }
+ it { is_expected.to be_allowed(:read_package) }
+ it { is_expected.to be_allowed(:read_project) }
+ it { is_expected.to be_disallowed(:destroy_package) }
+
+ it_behaves_like 'package access with repository disabled'
+ end
end
- context 'a deploy token with write_package_registry scope' do
- let(:deploy_token) { create(:deploy_token, write_package_registry: true) }
+ context 'public project' do
+ let(:project) { public_project }
- it { is_expected.to be_allowed(:create_package) }
- it { is_expected.to be_allowed(:read_package) }
- it { is_expected.to be_allowed(:read_project) }
- it { is_expected.to be_disallowed(:destroy_package) }
+ context 'a deploy token with read_registry scope' do
+ let(:deploy_token) { create(:deploy_token, read_registry: true, write_registry: false) }
- it_behaves_like 'package access with repository disabled'
+ it { is_expected.to be_allowed(:read_container_image) }
+ it { is_expected.to be_disallowed(:create_container_image) }
+
+ context 'with registry disabled' do
+ include_context 'registry disabled via project features'
+
+ it { is_expected.to be_disallowed(:read_container_image) }
+ it { is_expected.to be_disallowed(:create_container_image) }
+ end
+
+ context 'with registry private' do
+ include_context 'registry set to private via project features'
+
+ it { is_expected.to be_allowed(:read_container_image) }
+ it { is_expected.to be_disallowed(:create_container_image) }
+ end
+ end
+
+ context 'a deploy token with write_registry scope' do
+ let(:deploy_token) { create(:deploy_token, read_registry: false, write_registry: true) }
+
+ it { is_expected.to be_allowed(:read_container_image) }
+ it { is_expected.to be_allowed(:create_container_image) }
+
+ context 'with registry disabled' do
+ include_context 'registry disabled via project features'
+
+ it { is_expected.to be_disallowed(:read_container_image) }
+ it { is_expected.to be_disallowed(:create_container_image) }
+ end
+
+ context 'with registry private' do
+ include_context 'registry set to private via project features'
+
+ it { is_expected.to be_allowed(:read_container_image) }
+ it { is_expected.to be_allowed(:create_container_image) }
+ end
+ end
+
+ context 'a deploy token with no registry scope' do
+ let(:deploy_token) { create(:deploy_token, read_registry: false, write_registry: false) }
+
+ it { is_expected.to be_disallowed(:read_container_image) }
+ it { is_expected.to be_disallowed(:create_container_image) }
+ end
end
end
@@ -2251,4 +2343,25 @@ RSpec.describe ProjectPolicy do
it { is_expected.to be_disallowed(:register_project_runners) }
end
end
+
+ describe 'update_sentry_issue' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:role, :allowed) do
+ :owner | true
+ :maintainer | true
+ :developer | true
+ :reporter | false
+ :guest | false
+ end
+
+ let(:project) { public_project }
+ let(:current_user) { public_send(role) }
+
+ with_them do
+ it do
+ expect(subject.can?(:update_sentry_issue)).to be(allowed)
+ end
+ end
+ end
end