public_access_spec.rb 13.6 KB
Newer Older
1 2
require 'spec_helper'

3
describe "Public Project Access", feature: true  do
4 5
  include AccessMatchers

6
  let(:project) { create(:project, :public) }
7

8 9 10 11 12
  let(:owner)     { project.owner }
  let(:master)    { create(:user) }
  let(:developer) { create(:user) }
  let(:reporter)  { create(:user) }
  let(:guest)     { create(:user) }
13 14 15

  before do
    project.team << [master, :master]
16
    project.team << [developer, :developer]
17
    project.team << [reporter, :reporter]
18
    project.team << [guest, :guest]
19 20 21
  end

  describe "Project should be public" do
22
    describe '#public?' do
23
      subject { project.public? }
24 25
      it { is_expected.to be_truthy }
    end
26 27 28
  end

  describe "GET /:project_path" do
Vinnie Okada's avatar
Vinnie Okada committed
29
    subject { namespace_project_path(project.namespace, project) }
30

31 32
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
33
    it { is_expected.to be_allowed_for master }
34
    it { is_expected.to be_allowed_for developer }
35 36 37
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
38
    it { is_expected.to be_allowed_for :external }
39
    it { is_expected.to be_allowed_for :visitor }
40 41 42
  end

  describe "GET /:project_path/tree/master" do
Vinnie Okada's avatar
Vinnie Okada committed
43
    subject { namespace_project_tree_path(project.namespace, project, project.repository.root_ref) }
44

45 46
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
47
    it { is_expected.to be_allowed_for master }
48
    it { is_expected.to be_allowed_for developer }
49 50 51
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
52
    it { is_expected.to be_allowed_for :external }
53
    it { is_expected.to be_allowed_for :visitor }
54 55 56
  end

  describe "GET /:project_path/commits/master" do
Vinnie Okada's avatar
Vinnie Okada committed
57
    subject { namespace_project_commits_path(project.namespace, project, project.repository.root_ref, limit: 1) }
58

59 60
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
61
    it { is_expected.to be_allowed_for master }
62
    it { is_expected.to be_allowed_for developer }
63 64 65
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
66
    it { is_expected.to be_allowed_for :external }
67
    it { is_expected.to be_allowed_for :visitor }
68 69 70
  end

  describe "GET /:project_path/commit/:sha" do
Vinnie Okada's avatar
Vinnie Okada committed
71
    subject { namespace_project_commit_path(project.namespace, project, project.repository.commit) }
72

73 74
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
75
    it { is_expected.to be_allowed_for master }
76
    it { is_expected.to be_allowed_for developer }
77 78 79
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
80
    it { is_expected.to be_allowed_for :external }
81
    it { is_expected.to be_allowed_for :visitor }
82 83 84
  end

  describe "GET /:project_path/compare" do
Vinnie Okada's avatar
Vinnie Okada committed
85
    subject { namespace_project_compare_index_path(project.namespace, project) }
86

87 88
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
89
    it { is_expected.to be_allowed_for master }
90
    it { is_expected.to be_allowed_for developer }
91 92 93
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
94
    it { is_expected.to be_allowed_for :external }
95
    it { is_expected.to be_allowed_for :visitor }
96 97
  end

98 99
  describe "GET /:project_path/project_members" do
    subject { namespace_project_project_members_path(project.namespace, project) }
100

101 102
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
103
    it { is_expected.to be_allowed_for master }
104 105 106 107 108 109
    it { is_expected.to be_allowed_for developer }
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_allowed_for :visitor }
    it { is_expected.to be_allowed_for :external }
110 111
  end

112 113 114 115 116 117
  describe "GET /:project_path/builds" do
    subject { namespace_project_builds_path(project.namespace, project) }

    context "when allowed for public" do
      before { project.update(public_builds: true) }

118 119
      it { is_expected.to be_allowed_for :admin }
      it { is_expected.to be_allowed_for owner }
120
      it { is_expected.to be_allowed_for master }
121
      it { is_expected.to be_allowed_for developer }
122 123 124
      it { is_expected.to be_allowed_for reporter }
      it { is_expected.to be_allowed_for guest }
      it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
125
      it { is_expected.to be_allowed_for :external }
126 127 128 129 130 131
      it { is_expected.to be_allowed_for :visitor }
    end

    context "when disallowed for public" do
      before { project.update(public_builds: false) }

132 133
      it { is_expected.to be_allowed_for :admin }
      it { is_expected.to be_allowed_for owner }
134
      it { is_expected.to be_allowed_for master }
135
      it { is_expected.to be_allowed_for developer }
136 137 138
      it { is_expected.to be_allowed_for reporter }
      it { is_expected.to be_denied_for guest }
      it { is_expected.to be_denied_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
139
      it { is_expected.to be_denied_for :external }
140 141 142 143 144 145 146 147 148 149 150 151
      it { is_expected.to be_denied_for :visitor }
    end
  end

  describe "GET /:project_path/builds/:id" do
    let(:commit) { create(:ci_commit, project: project) }
    let(:build) { create(:ci_build, commit: commit) }
    subject { namespace_project_build_path(project.namespace, project, build.id) }

    context "when allowed for public" do
      before { project.update(public_builds: true) }

152 153
      it { is_expected.to be_allowed_for :admin }
      it { is_expected.to be_allowed_for owner }
154
      it { is_expected.to be_allowed_for master }
155
      it { is_expected.to be_allowed_for developer }
156 157 158
      it { is_expected.to be_allowed_for reporter }
      it { is_expected.to be_allowed_for guest }
      it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
159
      it { is_expected.to be_allowed_for :external }
160 161 162 163 164 165
      it { is_expected.to be_allowed_for :visitor }
    end

    context "when disallowed for public" do
      before { project.update(public_builds: false) }

166 167
      it { is_expected.to be_allowed_for :admin }
      it { is_expected.to be_allowed_for owner }
168
      it { is_expected.to be_allowed_for master }
169
      it { is_expected.to be_allowed_for developer }
170 171 172
      it { is_expected.to be_allowed_for reporter }
      it { is_expected.to be_denied_for guest }
      it { is_expected.to be_denied_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
173
      it { is_expected.to be_denied_for :external }
174 175 176 177
      it { is_expected.to be_denied_for :visitor }
    end
  end

178
  describe "GET /:project_path/blob" do
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
179 180 181
    let(:commit) { project.repository.commit }

    subject { namespace_project_blob_path(project.namespace, project, File.join(commit.id, '.gitignore')) }
182

183 184
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
185
    it { is_expected.to be_allowed_for master }
186
    it { is_expected.to be_allowed_for developer }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
187 188 189 190
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_allowed_for :visitor }
191 192 193
  end

  describe "GET /:project_path/edit" do
Vinnie Okada's avatar
Vinnie Okada committed
194
    subject { edit_namespace_project_path(project.namespace, project) }
195

196 197
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
198
    it { is_expected.to be_allowed_for master }
199
    it { is_expected.to be_denied_for developer }
200 201 202
    it { is_expected.to be_denied_for reporter }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
203
    it { is_expected.to be_denied_for :external }
204
    it { is_expected.to be_denied_for :visitor }
205 206 207
  end

  describe "GET /:project_path/deploy_keys" do
Vinnie Okada's avatar
Vinnie Okada committed
208
    subject { namespace_project_deploy_keys_path(project.namespace, project) }
209

210 211
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
212
    it { is_expected.to be_allowed_for master }
213
    it { is_expected.to be_denied_for developer }
214 215 216
    it { is_expected.to be_denied_for reporter }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
217
    it { is_expected.to be_denied_for :external }
218
    it { is_expected.to be_denied_for :visitor }
219 220 221
  end

  describe "GET /:project_path/issues" do
Vinnie Okada's avatar
Vinnie Okada committed
222
    subject { namespace_project_issues_path(project.namespace, project) }
223

224 225
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
226
    it { is_expected.to be_allowed_for master }
227
    it { is_expected.to be_allowed_for developer }
228 229 230
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
231
    it { is_expected.to be_allowed_for :external }
232
    it { is_expected.to be_allowed_for :visitor }
233 234
  end

235 236 237 238
  describe "GET /:project_path/issues/:id/edit" do
    let(:issue) { create(:issue, project: project) }
    subject { edit_namespace_project_issue_path(project.namespace, project, issue) }

239 240
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
241
    it { is_expected.to be_allowed_for master }
242
    it { is_expected.to be_allowed_for developer }
243 244 245
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
246
    it { is_expected.to be_denied_for :external }
247 248 249
    it { is_expected.to be_denied_for :visitor }
  end

250
  describe "GET /:project_path/snippets" do
Vinnie Okada's avatar
Vinnie Okada committed
251
    subject { namespace_project_snippets_path(project.namespace, project) }
252

253 254
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
255
    it { is_expected.to be_allowed_for master }
256
    it { is_expected.to be_allowed_for developer }
257 258 259
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
260
    it { is_expected.to be_allowed_for :external }
261
    it { is_expected.to be_allowed_for :visitor }
262 263 264
  end

  describe "GET /:project_path/snippets/new" do
Vinnie Okada's avatar
Vinnie Okada committed
265
    subject { new_namespace_project_snippet_path(project.namespace, project) }
266

267 268
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
269
    it { is_expected.to be_allowed_for master }
270
    it { is_expected.to be_allowed_for developer }
271 272 273
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
274
    it { is_expected.to be_denied_for :external }
275
    it { is_expected.to be_denied_for :visitor }
276 277 278
  end

  describe "GET /:project_path/merge_requests" do
Vinnie Okada's avatar
Vinnie Okada committed
279
    subject { namespace_project_merge_requests_path(project.namespace, project) }
280

281 282
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
283
    it { is_expected.to be_allowed_for master }
284
    it { is_expected.to be_allowed_for developer }
285 286 287
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
288
    it { is_expected.to be_allowed_for :external }
289
    it { is_expected.to be_allowed_for :visitor }
290 291 292
  end

  describe "GET /:project_path/merge_requests/new" do
Vinnie Okada's avatar
Vinnie Okada committed
293
    subject { new_namespace_project_merge_request_path(project.namespace, project) }
294

295 296
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
297
    it { is_expected.to be_allowed_for master }
298
    it { is_expected.to be_allowed_for developer }
299 300 301
    it { is_expected.to be_denied_for reporter }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
302
    it { is_expected.to be_denied_for :external }
303
    it { is_expected.to be_denied_for :visitor }
304 305 306
  end

  describe "GET /:project_path/branches" do
Vinnie Okada's avatar
Vinnie Okada committed
307
    subject { namespace_project_branches_path(project.namespace, project) }
308 309 310

    before do
      # Speed increase
311
      allow_any_instance_of(Project).to receive(:branches).and_return([])
312 313
    end

314 315
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
316
    it { is_expected.to be_allowed_for master }
317
    it { is_expected.to be_allowed_for developer }
318 319 320
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
321
    it { is_expected.to be_allowed_for :external }
322
    it { is_expected.to be_allowed_for :visitor }
323 324 325
  end

  describe "GET /:project_path/tags" do
Vinnie Okada's avatar
Vinnie Okada committed
326
    subject { namespace_project_tags_path(project.namespace, project) }
327 328 329

    before do
      # Speed increase
330
      allow_any_instance_of(Project).to receive(:tags).and_return([])
331 332
    end

333 334
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
335
    it { is_expected.to be_allowed_for master }
336
    it { is_expected.to be_allowed_for developer }
337 338 339
    it { is_expected.to be_allowed_for reporter }
    it { is_expected.to be_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
340
    it { is_expected.to be_allowed_for :external }
341
    it { is_expected.to be_allowed_for :visitor }
342 343 344
  end

  describe "GET /:project_path/hooks" do
Vinnie Okada's avatar
Vinnie Okada committed
345
    subject { namespace_project_hooks_path(project.namespace, project) }
346

347 348
    it { is_expected.to be_allowed_for :admin }
    it { is_expected.to be_allowed_for owner }
349
    it { is_expected.to be_allowed_for master }
350
    it { is_expected.to be_denied_for developer }
351 352 353
    it { is_expected.to be_denied_for reporter }
    it { is_expected.to be_denied_for guest }
    it { is_expected.to be_denied_for :user }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
354
    it { is_expected.to be_denied_for :external }
355
    it { is_expected.to be_denied_for :visitor }
356 357
  end
end