BigW Consortium Gitlab

private_access_spec.rb 6.63 KB
Newer Older
1 2
require 'spec_helper'

3
describe "Private Project Access", feature: true  do
4
  let(:project) { create(:project) }
5 6 7 8 9 10 11 12 13 14 15 16 17

  let(:master)   { create(:user) }
  let(:guest)    { create(:user) }
  let(:reporter) { create(:user) }

  before do
    # full access
    project.team << [master, :master]

    # readonly
    project.team << [reporter, :reporter]
  end

18 19 20
  describe "Project should be private" do
    subject { project }

21 22 23 24
    describe '#private?' do
      subject { super().private? }
      it { is_expected.to be_truthy }
    end
25 26
  end

27 28 29
  describe "GET /:project_path" do
    subject { project_path(project) }

30 31 32 33 34 35
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
36 37 38 39 40
  end

  describe "GET /:project_path/tree/master" do
    subject { project_tree_path(project, project.repository.root_ref) }

41 42 43 44 45 46
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
47 48 49 50 51
  end

  describe "GET /:project_path/commits/master" do
    subject { project_commits_path(project, project.repository.root_ref, limit: 1) }

52 53 54 55 56 57
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
58 59 60 61 62
  end

  describe "GET /:project_path/commit/:sha" do
    subject { project_commit_path(project, project.repository.commit) }

63 64 65 66 67 68
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
69 70 71 72 73
  end

  describe "GET /:project_path/compare" do
    subject { project_compare_index_path(project) }

74 75 76 77 78 79
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
80 81 82 83 84
  end

  describe "GET /:project_path/team" do
    subject { project_team_index_path(project) }

85 86 87 88 89 90
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_denied_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
91 92 93 94 95
  end

  describe "GET /:project_path/blob" do
    before do
      commit = project.repository.commit
Dmitriy Zaporozhets committed
96
      path = '.gitignore'
97 98 99
      @blob_path = project_blob_path(project, File.join(commit.id, path))
    end

100 101 102 103 104 105
    it { expect(@blob_path).to be_allowed_for master }
    it { expect(@blob_path).to be_allowed_for reporter }
    it { expect(@blob_path).to be_allowed_for :admin }
    it { expect(@blob_path).to be_denied_for guest }
    it { expect(@blob_path).to be_denied_for :user }
    it { expect(@blob_path).to be_denied_for :visitor }
106 107 108 109 110
  end

  describe "GET /:project_path/edit" do
    subject { edit_project_path(project) }

111 112 113 114 115 116
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_denied_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
117 118 119 120 121
  end

  describe "GET /:project_path/deploy_keys" do
    subject { project_deploy_keys_path(project) }

122 123 124 125 126 127
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_denied_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
128 129 130 131 132
  end

  describe "GET /:project_path/issues" do
    subject { project_issues_path(project) }

133 134 135 136 137 138
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
139 140 141 142 143
  end

  describe "GET /:project_path/snippets" do
    subject { project_snippets_path(project) }

144 145 146 147 148 149
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
150 151 152 153 154
  end

  describe "GET /:project_path/merge_requests" do
    subject { project_merge_requests_path(project) }

155 156 157 158 159 160
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
161 162 163 164 165 166 167
  end

  describe "GET /:project_path/branches" do
    subject { project_branches_path(project) }

    before do
      # Speed increase
168
      allow_any_instance_of(Project).to receive(:branches).and_return([])
169 170
    end

171 172 173 174 175 176
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
177 178 179 180 181 182 183
  end

  describe "GET /:project_path/tags" do
    subject { project_tags_path(project) }

    before do
      # Speed increase
184
      allow_any_instance_of(Project).to receive(:tags).and_return([])
185 186
    end

187 188 189 190 191 192
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
193 194 195 196 197
  end

  describe "GET /:project_path/hooks" do
    subject { project_hooks_path(project) }

198 199 200 201 202 203
    it { is_expected.to be_allowed_for master }
    it { is_expected.to be_denied_for reporter }
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
    it { is_expected.to be_denied_for :visitor }
204 205
  end
end