debian-mirror-gitlab/spec/policies/project_snippet_policy_spec.rb

158 lines
3.7 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2018-03-17 18:26:18 +05:30
# Snippet visibility scenarios are included in more details in spec/support/snippet_visibility.rb
2017-09-10 17:25:29 +05:30
describe ProjectSnippetPolicy do
2017-08-17 22:00:37 +05:30
let(:regular_user) { create(:user) }
let(:external_user) { create(:user, :external) }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, :public) }
2019-05-18 00:54:41 +05:30
let(:snippet) { create(:project_snippet, snippet_visibility, project: project) }
2017-08-17 22:00:37 +05:30
let(:author_permissions) do
[
:update_project_snippet,
:admin_project_snippet
]
end
2019-05-18 00:54:41 +05:30
subject { described_class.new(current_user, snippet) }
2017-08-17 22:00:37 +05:30
context 'public snippet' do
2019-05-18 00:54:41 +05:30
let(:snippet_visibility) { :public }
2017-08-17 22:00:37 +05:30
context 'no user' do
2019-05-18 00:54:41 +05:30
let(:current_user) { nil }
2017-08-17 22:00:37 +05:30
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_project_snippet)
expect_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'regular user' do
2019-05-18 00:54:41 +05:30
let(:current_user) { regular_user }
2017-08-17 22:00:37 +05:30
it do
2019-02-02 18:00:53 +05:30
expect_allowed(:read_project_snippet, :create_note)
2017-09-10 17:25:29 +05:30
expect_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'external user' do
2019-05-18 00:54:41 +05:30
let(:current_user) { external_user }
2017-08-17 22:00:37 +05:30
it do
2019-02-02 18:00:53 +05:30
expect_allowed(:read_project_snippet, :create_note)
2017-09-10 17:25:29 +05:30
expect_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
end
context 'internal snippet' do
2019-05-18 00:54:41 +05:30
let(:snippet_visibility) { :internal }
2017-08-17 22:00:37 +05:30
context 'no user' do
2019-05-18 00:54:41 +05:30
let(:current_user) { nil }
2017-08-17 22:00:37 +05:30
it do
2017-09-10 17:25:29 +05:30
expect_disallowed(:read_project_snippet)
expect_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'regular user' do
2019-05-18 00:54:41 +05:30
let(:current_user) { regular_user }
2017-08-17 22:00:37 +05:30
it do
2019-02-02 18:00:53 +05:30
expect_allowed(:read_project_snippet, :create_note)
2017-09-10 17:25:29 +05:30
expect_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'external user' do
2019-05-18 00:54:41 +05:30
let(:current_user) { external_user }
2017-08-17 22:00:37 +05:30
it do
2019-02-02 18:00:53 +05:30
expect_disallowed(:read_project_snippet, :create_note)
2017-09-10 17:25:29 +05:30
expect_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
2019-05-18 00:54:41 +05:30
context 'project team member' do
before do
project.add_developer(external_user)
end
2017-08-17 22:00:37 +05:30
2019-05-18 00:54:41 +05:30
it do
expect_allowed(:read_project_snippet, :create_note)
expect_disallowed(*author_permissions)
end
2017-08-17 22:00:37 +05:30
end
end
end
context 'private snippet' do
2019-05-18 00:54:41 +05:30
let(:snippet_visibility) { :private }
2017-08-17 22:00:37 +05:30
context 'no user' do
2019-05-18 00:54:41 +05:30
let(:current_user) { nil }
2017-08-17 22:00:37 +05:30
it do
2017-09-10 17:25:29 +05:30
expect_disallowed(:read_project_snippet)
expect_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'regular user' do
2019-05-18 00:54:41 +05:30
let(:current_user) { regular_user }
2017-08-17 22:00:37 +05:30
it do
2019-02-02 18:00:53 +05:30
expect_disallowed(:read_project_snippet, :create_note)
2017-09-10 17:25:29 +05:30
expect_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
2019-05-18 00:54:41 +05:30
context 'snippet author' do
let(:snippet) { create(:project_snippet, :private, author: regular_user, project: project) }
2017-08-17 22:00:37 +05:30
2019-05-18 00:54:41 +05:30
it do
expect_allowed(:read_project_snippet, :create_note)
expect_allowed(*author_permissions)
end
2017-08-17 22:00:37 +05:30
end
2019-05-18 00:54:41 +05:30
context 'project team member normal user' do
before do
project.add_developer(regular_user)
end
2017-08-17 22:00:37 +05:30
2019-05-18 00:54:41 +05:30
it do
expect_allowed(:read_project_snippet, :create_note)
expect_disallowed(*author_permissions)
end
2017-08-17 22:00:37 +05:30
end
end
2019-05-18 00:54:41 +05:30
context 'external user' do
context 'project team member' do
let(:current_user) { external_user }
2017-08-17 22:00:37 +05:30
2019-05-18 00:54:41 +05:30
before do
project.add_developer(external_user)
end
2017-08-17 22:00:37 +05:30
2019-05-18 00:54:41 +05:30
it do
expect_allowed(:read_project_snippet, :create_note)
expect_disallowed(*author_permissions)
end
2017-08-17 22:00:37 +05:30
end
end
context 'admin user' do
2019-05-18 00:54:41 +05:30
let(:snippet_visibility) { :private }
let(:current_user) { create(:admin) }
2017-08-17 22:00:37 +05:30
it do
2019-02-02 18:00:53 +05:30
expect_allowed(:read_project_snippet, :create_note)
2017-09-10 17:25:29 +05:30
expect_allowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
end
end