private_access_spec.rb 4.5 KB
Newer Older
1 2
# frozen_string_literal: true

Felipe Artur's avatar
Felipe Artur committed
3 4
require 'rails_helper'

5
describe 'Private Group access' do
Felipe Artur's avatar
Felipe Artur committed
6 7
  include AccessMatchers

8
  let(:group)   { create(:group, :private) }
9
  let(:project) { create(:project, :private, group: group) }
10 11 12 13
  let(:project_guest) do
    create(:user) do |user|
      project.add_guest(user)
    end
Felipe Artur's avatar
Felipe Artur committed
14 15
  end

16 17 18 19
  describe "Group should be private" do
    describe '#private?' do
      subject { group.private? }
      it { is_expected.to be_truthy }
Felipe Artur's avatar
Felipe Artur committed
20
    end
21
  end
Felipe Artur's avatar
Felipe Artur committed
22

23 24 25
  describe 'GET /groups/:path' do
    subject { group_path(group) }

26 27
    it { is_expected.to be_allowed_for(:admin) }
    it { is_expected.to be_allowed_for(:owner).of(group) }
28
    it { is_expected.to be_allowed_for(:maintainer).of(group) }
29 30 31
    it { is_expected.to be_allowed_for(:developer).of(group) }
    it { is_expected.to be_allowed_for(:reporter).of(group) }
    it { is_expected.to be_allowed_for(:guest).of(group) }
32
    it { is_expected.to be_allowed_for(project_guest) }
33 34 35
    it { is_expected.to be_denied_for(:user) }
    it { is_expected.to be_denied_for(:external) }
    it { is_expected.to be_denied_for(:visitor) }
Felipe Artur's avatar
Felipe Artur committed
36 37
  end

38 39 40
  describe 'GET /groups/:path/issues' do
    subject { issues_group_path(group) }

41 42
    it { is_expected.to be_allowed_for(:admin) }
    it { is_expected.to be_allowed_for(:owner).of(group) }
43
    it { is_expected.to be_allowed_for(:maintainer).of(group) }
44 45 46
    it { is_expected.to be_allowed_for(:developer).of(group) }
    it { is_expected.to be_allowed_for(:reporter).of(group) }
    it { is_expected.to be_allowed_for(:guest).of(group) }
47
    it { is_expected.to be_allowed_for(project_guest) }
48 49 50
    it { is_expected.to be_denied_for(:user) }
    it { is_expected.to be_denied_for(:external) }
    it { is_expected.to be_denied_for(:visitor) }
51
  end
Felipe Artur's avatar
Felipe Artur committed
52

53
  describe 'GET /groups/:path/merge_requests' do
54
    let(:project) { create(:project, :private, :repository, group: group) }
55 56
    subject { merge_requests_group_path(group) }

57 58
    it { is_expected.to be_allowed_for(:admin) }
    it { is_expected.to be_allowed_for(:owner).of(group) }
59
    it { is_expected.to be_allowed_for(:maintainer).of(group) }
60 61 62
    it { is_expected.to be_allowed_for(:developer).of(group) }
    it { is_expected.to be_allowed_for(:reporter).of(group) }
    it { is_expected.to be_allowed_for(:guest).of(group) }
63
    it { is_expected.to be_allowed_for(project_guest) }
64 65 66
    it { is_expected.to be_denied_for(:user) }
    it { is_expected.to be_denied_for(:external) }
    it { is_expected.to be_denied_for(:visitor) }
Felipe Artur's avatar
Felipe Artur committed
67 68 69
  end

  describe 'GET /groups/:path/group_members' do
70 71
    subject { group_group_members_path(group) }

72 73
    it { is_expected.to be_allowed_for(:admin) }
    it { is_expected.to be_allowed_for(:owner).of(group) }
74
    it { is_expected.to be_allowed_for(:maintainer).of(group) }
75 76 77
    it { is_expected.to be_allowed_for(:developer).of(group) }
    it { is_expected.to be_allowed_for(:reporter).of(group) }
    it { is_expected.to be_allowed_for(:guest).of(group) }
78
    it { is_expected.to be_allowed_for(project_guest) }
79 80 81
    it { is_expected.to be_denied_for(:user) }
    it { is_expected.to be_denied_for(:external) }
    it { is_expected.to be_denied_for(:visitor) }
Felipe Artur's avatar
Felipe Artur committed
82 83 84
  end

  describe 'GET /groups/:path/edit' do
85 86
    subject { edit_group_path(group) }

87 88
    it { is_expected.to be_allowed_for(:admin) }
    it { is_expected.to be_allowed_for(:owner).of(group) }
89
    it { is_expected.to be_denied_for(:maintainer).of(group) }
90 91 92 93 94 95 96
    it { is_expected.to be_denied_for(:developer).of(group) }
    it { is_expected.to be_denied_for(:reporter).of(group) }
    it { is_expected.to be_denied_for(:guest).of(group) }
    it { is_expected.to be_denied_for(project_guest) }
    it { is_expected.to be_denied_for(:user) }
    it { is_expected.to be_denied_for(:visitor) }
    it { is_expected.to be_denied_for(:external) }
Felipe Artur's avatar
Felipe Artur committed
97
  end
98 99 100

  describe 'GET /groups/:path for shared projects' do
    let(:project) { create(:project, :public) }
101

102
    before do
Małgorzata Ksionek's avatar
Małgorzata Ksionek committed
103
      create(:project_group_link, project: project, group: group)
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    end

    subject { group_path(group) }

    it { is_expected.to be_allowed_for(:admin) }
    it { is_expected.to be_allowed_for(:owner).of(group) }
    it { is_expected.to be_allowed_for(:maintainer).of(group) }
    it { is_expected.to be_allowed_for(:developer).of(group) }
    it { is_expected.to be_allowed_for(:reporter).of(group) }
    it { is_expected.to be_allowed_for(:guest).of(group) }
    it { is_expected.to be_denied_for(project_guest) }
    it { is_expected.to be_denied_for(:user) }
    it { is_expected.to be_denied_for(:external) }
    it { is_expected.to be_denied_for(:visitor) }
  end
Felipe Artur's avatar
Felipe Artur committed
119
end