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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

174 lines
4.6 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
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
2020-07-28 23:09:34 +05:30
RSpec.describe PersonalSnippetPolicy do
2017-08-17 22:00:37 +05:30
let(:regular_user) { create(:user) }
let(:external_user) { create(:user, :external) }
let(:admin_user) { create(:user, :admin) }
let(:author_permissions) do
[
2020-03-13 15:44:24 +05:30
:update_snippet,
:admin_snippet
2017-08-17 22:00:37 +05:30
]
end
def permissions(user)
2017-09-10 17:25:29 +05:30
described_class.new(user, snippet)
2017-08-17 22:00:37 +05:30
end
2020-05-24 23:13:21 +05:30
shared_examples 'admin access with admin mode' do
context 'admin user', :enable_admin_mode do
2019-12-26 22:10:19 +05:30
subject { permissions(admin_user) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_allowed(:read_snippet)
2019-12-26 22:10:19 +05:30
is_expected.to be_allowed(:create_note)
is_expected.to be_allowed(:award_emoji)
is_expected.to be_allowed(*author_permissions)
end
end
end
2017-08-17 22:00:37 +05:30
context 'public snippet' do
let(:snippet) { create(:personal_snippet, :public) }
context 'no user' do
subject { permissions(nil) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_allowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_disallowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_disallowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'regular user' do
subject { permissions(regular_user) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_allowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_allowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_allowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'author' do
subject { permissions(snippet.author) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_allowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_allowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_allowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_allowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
it_behaves_like 'admin access with admin mode'
2017-08-17 22:00:37 +05:30
end
context 'internal snippet' do
let(:snippet) { create(:personal_snippet, :internal) }
context 'no user' do
subject { permissions(nil) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_disallowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_disallowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_disallowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'regular user' do
subject { permissions(regular_user) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_allowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_allowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_allowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'external user' do
subject { permissions(external_user) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_disallowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_disallowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_disallowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'snippet author' do
subject { permissions(snippet.author) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_allowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_allowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_allowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_allowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
it_behaves_like 'admin access with admin mode'
2017-08-17 22:00:37 +05:30
end
context 'private snippet' do
let(:snippet) { create(:project_snippet, :private) }
context 'no user' do
subject { permissions(nil) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_disallowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_disallowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_disallowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'regular user' do
subject { permissions(regular_user) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_disallowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_disallowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_disallowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'external user' do
subject { permissions(external_user) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_disallowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_disallowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_disallowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'snippet author' do
subject { permissions(snippet.author) }
it do
2020-03-13 15:44:24 +05:30
is_expected.to be_allowed(:read_snippet)
2019-07-31 22:56:46 +05:30
is_expected.to be_allowed(:create_note)
2018-05-09 12:01:36 +05:30
is_expected.to be_allowed(:award_emoji)
2017-09-10 17:25:29 +05:30
is_expected.to be_allowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
it_behaves_like 'admin access with admin mode'
2017-08-17 22:00:37 +05:30
end
end