project_access_spec.rb 7.2 KB
Newer Older
G
gitlabhq 已提交
1 2
require 'spec_helper'

3
describe "Application access" do
R
randx 已提交
4 5 6 7
  describe "GET /" do
    it { root_path.should be_allowed_for :admin }
    it { root_path.should be_allowed_for :user }
    it { root_path.should be_denied_for :visitor }
G
gitlabhq 已提交
8 9
  end

N
Nihad Abbasov 已提交
10
  describe "GET /projects/new" do
R
randx 已提交
11 12 13
    it { new_project_path.should be_allowed_for :admin }
    it { new_project_path.should be_allowed_for :user }
    it { new_project_path.should be_denied_for :visitor }
G
gitlabhq 已提交
14 15 16
  end

  describe "Project" do
D
Dmitriy Zaporozhets 已提交
17
    let(:project)  { create(:project_with_code) }
R
Robert Speicher 已提交
18 19 20 21 22

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

N
Nihad Abbasov 已提交
23
    before do
G
gitlabhq 已提交
24
      # full access
25
      project.team << [master, :master]
R
Robert Speicher 已提交
26

G
gitlabhq 已提交
27
      # readonly
28
      project.team << [reporter, :reporter]
G
gitlabhq 已提交
29 30
    end

N
Nihad Abbasov 已提交
31
    describe "GET /project_code" do
R
Robert Speicher 已提交
32 33 34 35
      subject { project_path(project) }

      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
36
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
37 38 39 40 41 42
      it { should be_denied_for guest }
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
    end

    describe "GET /project_code/tree/master" do
D
Dmitriy Zaporozhets 已提交
43
      subject { project_tree_path(project, project.repository.root_ref) }
R
Robert Speicher 已提交
44

R
Robert Speicher 已提交
45 46
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
47
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
48
      it { should be_denied_for guest }
R
Robert Speicher 已提交
49 50
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
G
gitlabhq 已提交
51 52
    end

R
Robert Speicher 已提交
53
    describe "GET /project_code/commits/master" do
D
Dmitriy Zaporozhets 已提交
54
      subject { project_commits_path(project, project.repository.root_ref, limit: 1) }
R
Robert Speicher 已提交
55

R
Robert Speicher 已提交
56 57
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
58
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
59
      it { should be_denied_for guest }
R
Robert Speicher 已提交
60 61
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
G
gitlabhq 已提交
62 63
    end

R
Robert Speicher 已提交
64
    describe "GET /project_code/commit/:sha" do
65
      subject { project_commit_path(project, project.repository.commit) }
R
Robert Speicher 已提交
66

R
Robert Speicher 已提交
67 68
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
69
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
70
      it { should be_denied_for guest }
R
Robert Speicher 已提交
71 72
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
G
gitlabhq 已提交
73 74
    end

R
Robert Speicher 已提交
75 76
    describe "GET /project_code/compare" do
      subject { project_compare_index_path(project) }
R
Robert Speicher 已提交
77

R
Robert Speicher 已提交
78 79
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
80
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
81
      it { should be_denied_for guest }
R
Robert Speicher 已提交
82 83
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
G
gitlabhq 已提交
84 85
    end

N
Nihad Abbasov 已提交
86
    describe "GET /project_code/team" do
R
Robert Speicher 已提交
87
      subject { project_team_index_path(project) }
R
Robert Speicher 已提交
88

R
Robert Speicher 已提交
89 90
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
91
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
92
      it { should be_denied_for guest }
R
Robert Speicher 已提交
93 94
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
G
gitlabhq 已提交
95 96
    end

N
Nihad Abbasov 已提交
97
    describe "GET /project_code/wall" do
98
      subject { project_wall_path(project) }
R
Robert Speicher 已提交
99

R
Robert Speicher 已提交
100 101
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
102
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
103
      it { should be_denied_for guest }
R
Robert Speicher 已提交
104 105
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
G
gitlabhq 已提交
106 107
    end

N
Nihad Abbasov 已提交
108 109
    describe "GET /project_code/blob" do
      before do
110
        commit = project.repository.commit
R
Robert Speicher 已提交
111
        path = commit.tree.contents.select { |i| i.is_a?(Grit::Blob)}.first.name
R
Robert Speicher 已提交
112
        @blob_path = project_blob_path(project, File.join(commit.id, path))
G
gitlabhq 已提交
113 114
      end

R
Robert Speicher 已提交
115 116
      it { @blob_path.should be_allowed_for master }
      it { @blob_path.should be_allowed_for reporter }
117
      it { @blob_path.should be_allowed_for :admin }
R
Robert Speicher 已提交
118
      it { @blob_path.should be_denied_for guest }
G
gitlabhq 已提交
119 120
      it { @blob_path.should be_denied_for :user }
      it { @blob_path.should be_denied_for :visitor }
G
gitlabhq 已提交
121 122
    end

N
Nihad Abbasov 已提交
123
    describe "GET /project_code/edit" do
R
Robert Speicher 已提交
124
      subject { edit_project_path(project) }
R
Robert Speicher 已提交
125

R
Robert Speicher 已提交
126 127
      it { should be_allowed_for master }
      it { should be_denied_for reporter }
128
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
129
      it { should be_denied_for guest }
R
Robert Speicher 已提交
130 131
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
G
gitlabhq 已提交
132 133
    end

M
miks 已提交
134
    describe "GET /project_code/deploy_keys" do
R
Robert Speicher 已提交
135
      subject { project_deploy_keys_path(project) }
R
Robert Speicher 已提交
136

R
Robert Speicher 已提交
137 138
      it { should be_allowed_for master }
      it { should be_denied_for reporter }
139
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
140
      it { should be_denied_for guest }
R
Robert Speicher 已提交
141 142
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
M
miks 已提交
143 144
    end

N
Nihad Abbasov 已提交
145
    describe "GET /project_code/issues" do
R
Robert Speicher 已提交
146
      subject { project_issues_path(project) }
R
Robert Speicher 已提交
147

R
Robert Speicher 已提交
148 149
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
150
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
151
      it { should be_denied_for guest }
R
Robert Speicher 已提交
152 153
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
G
gitlabhq 已提交
154
    end
G
gitlabhq 已提交
155

N
Nihad Abbasov 已提交
156
    describe "GET /project_code/snippets" do
R
Robert Speicher 已提交
157
      subject { project_snippets_path(project) }
R
Robert Speicher 已提交
158

R
Robert Speicher 已提交
159 160
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
161
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
162
      it { should be_denied_for guest }
R
Robert Speicher 已提交
163 164
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
G
gitlabhq 已提交
165
    end
166 167

    describe "GET /project_code/merge_requests" do
R
Robert Speicher 已提交
168
      subject { project_merge_requests_path(project) }
R
Robert Speicher 已提交
169

R
Robert Speicher 已提交
170 171
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
172
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
173
      it { should be_denied_for guest }
R
Robert Speicher 已提交
174 175
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
176
    end
177 178

    describe "GET /project_code/repository" do
R
Robert Speicher 已提交
179
      subject { project_repository_path(project) }
R
Robert Speicher 已提交
180

R
Robert Speicher 已提交
181 182
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
183
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
184
      it { should be_denied_for guest }
R
Robert Speicher 已提交
185 186
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
187 188 189
    end

    describe "GET /project_code/repository/branches" do
R
Robert Speicher 已提交
190
      subject { branches_project_repository_path(project) }
R
Robert Speicher 已提交
191

R
Robert Speicher 已提交
192 193 194 195 196
      before do
        # Speed increase
        Project.any_instance.stub(:branches).and_return([])
      end

R
Robert Speicher 已提交
197 198
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
199
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
200
      it { should be_denied_for guest }
R
Robert Speicher 已提交
201 202
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
203 204 205
    end

    describe "GET /project_code/repository/tags" do
R
Robert Speicher 已提交
206
      subject { tags_project_repository_path(project) }
R
Robert Speicher 已提交
207

R
Robert Speicher 已提交
208 209 210 211 212
      before do
        # Speed increase
        Project.any_instance.stub(:tags).and_return([])
      end

R
Robert Speicher 已提交
213 214
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
215
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
216
      it { should be_denied_for guest }
R
Robert Speicher 已提交
217 218
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
219 220 221
    end

    describe "GET /project_code/hooks" do
R
Robert Speicher 已提交
222
      subject { project_hooks_path(project) }
R
Robert Speicher 已提交
223

R
Robert Speicher 已提交
224 225
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
226
      it { should be_allowed_for :admin }
R
Robert Speicher 已提交
227
      it { should be_denied_for guest }
R
Robert Speicher 已提交
228 229
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
230
    end
G
gitlabhq 已提交
231 232
  end
end