project_access_spec.rb 7.59 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1 2
require 'spec_helper'

3
describe "Application access" do
randx's avatar
randx committed
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 }
gitlabhq's avatar
gitlabhq committed
8 9
  end

Nihad Abbasov's avatar
Nihad Abbasov committed
10
  describe "GET /projects/new" do
randx's avatar
randx committed
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 }
gitlabhq's avatar
gitlabhq committed
14 15 16
  end

  describe "Project" do
17 18 19 20 21 22
    let(:project)  { create(:project) }

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

Nihad Abbasov's avatar
Nihad Abbasov committed
23
    before do
gitlabhq's avatar
gitlabhq committed
24
      # full access
25 26
      project.users_projects.create(user: master, project_access: UsersProject::MASTER)

gitlabhq's avatar
gitlabhq committed
27
      # readonly
28
      project.users_projects.create(user: reporter, project_access: UsersProject::REPORTER)
gitlabhq's avatar
gitlabhq committed
29 30
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
31
    describe "GET /project_code" do
32 33 34 35 36 37 38 39 40 41 42 43
      subject { project_path(project) }

      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
      it { should be_denied_for :admin }
      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
      subject { project_tree_path(project, project.root_ref) }
Robert Speicher's avatar
Robert Speicher committed
44

45 46
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
47
      it { should be_denied_for :admin }
48
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
49 50
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
gitlabhq's avatar
gitlabhq committed
51 52
    end

53
    describe "GET /project_code/commits/master" do
54
      subject { project_commits_path(project, project.root_ref, limit: 1) }
Robert Speicher's avatar
Robert Speicher committed
55

56 57
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
58
      it { should be_denied_for :admin }
59
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
60 61
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
gitlabhq's avatar
gitlabhq committed
62 63
    end

64 65
    describe "GET /project_code/commit/:sha" do
      subject { project_commit_path(project, project.commit) }
Robert Speicher's avatar
Robert Speicher committed
66

67 68
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
69
      it { should be_denied_for :admin }
70
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
71 72
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
gitlabhq's avatar
gitlabhq committed
73 74
    end

75 76
    describe "GET /project_code/compare" do
      subject { project_compare_index_path(project) }
Robert Speicher's avatar
Robert Speicher committed
77

78 79
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
80
      it { should be_denied_for :admin }
81
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
82 83
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
gitlabhq's avatar
gitlabhq committed
84 85
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
86
    describe "GET /project_code/team" do
87
      subject { project_team_index_path(project) }
Robert Speicher's avatar
Robert Speicher committed
88

89 90
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
91
      it { should be_denied_for :admin }
92
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
93 94
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
gitlabhq's avatar
gitlabhq committed
95 96
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
97
    describe "GET /project_code/wall" do
98
      subject { wall_project_path(project) }
Robert Speicher's avatar
Robert Speicher committed
99

100 101
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
102
      it { should be_denied_for :admin }
103
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
104 105
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
gitlabhq's avatar
gitlabhq committed
106 107
    end

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

115 116
      it { @blob_path.should be_allowed_for master }
      it { @blob_path.should be_allowed_for reporter }
gitlabhq's avatar
gitlabhq committed
117
      it { @blob_path.should be_denied_for :admin }
118
      it { @blob_path.should be_denied_for guest }
gitlabhq's avatar
gitlabhq committed
119 120
      it { @blob_path.should be_denied_for :user }
      it { @blob_path.should be_denied_for :visitor }
gitlabhq's avatar
gitlabhq committed
121 122
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
123
    describe "GET /project_code/edit" do
124
      subject { edit_project_path(project) }
Robert Speicher's avatar
Robert Speicher committed
125

126 127
      it { should be_allowed_for master }
      it { should be_denied_for reporter }
Robert Speicher's avatar
Robert Speicher committed
128
      it { should be_denied_for :admin }
129
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
130 131
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
gitlabhq's avatar
gitlabhq committed
132 133
    end

miks's avatar
miks committed
134
    describe "GET /project_code/deploy_keys" do
135
      subject { project_deploy_keys_path(project) }
Robert Speicher's avatar
Robert Speicher committed
136

137 138
      it { should be_allowed_for master }
      it { should be_denied_for reporter }
Robert Speicher's avatar
Robert Speicher committed
139
      it { should be_denied_for :admin }
140
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
141 142
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
miks's avatar
miks committed
143 144
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
145
    describe "GET /project_code/issues" do
146
      subject { project_issues_path(project) }
Robert Speicher's avatar
Robert Speicher committed
147

148 149
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
150
      it { should be_denied_for :admin }
151
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
152 153
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
gitlabhq's avatar
gitlabhq committed
154
    end
gitlabhq's avatar
gitlabhq committed
155

Nihad Abbasov's avatar
Nihad Abbasov committed
156
    describe "GET /project_code/snippets" do
157
      subject { project_snippets_path(project) }
Robert Speicher's avatar
Robert Speicher committed
158

159 160
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
161
      it { should be_denied_for :admin }
162
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
163 164
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
gitlabhq's avatar
gitlabhq committed
165
    end
166 167

    describe "GET /project_code/merge_requests" do
168
      subject { project_merge_requests_path(project) }
Robert Speicher's avatar
Robert Speicher committed
169

170 171
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
172
      it { should be_denied_for :admin }
173
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
174 175
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
176
    end
177 178

    describe "GET /project_code/repository" do
179
      subject { project_repository_path(project) }
Robert Speicher's avatar
Robert Speicher committed
180

181 182
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
183
      it { should be_denied_for :admin }
184
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
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
190
      subject { branches_project_repository_path(project) }
Robert Speicher's avatar
Robert Speicher committed
191

192 193 194 195 196
      before do
        # Speed increase
        Project.any_instance.stub(:branches).and_return([])
      end

197 198
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
199
      it { should be_denied_for :admin }
200
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
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
206
      subject { tags_project_repository_path(project) }
Robert Speicher's avatar
Robert Speicher committed
207

208 209 210 211 212
      before do
        # Speed increase
        Project.any_instance.stub(:tags).and_return([])
      end

213 214
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
215
      it { should be_denied_for :admin }
216
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
217 218
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
219 220 221
    end

    describe "GET /project_code/hooks" do
222
      subject { project_hooks_path(project) }
Robert Speicher's avatar
Robert Speicher committed
223

224 225
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
226
      it { should be_denied_for :admin }
227
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
228 229
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
230 231 232
    end

    describe "GET /project_code/files" do
233
      subject { files_project_path(project) }
Robert Speicher's avatar
Robert Speicher committed
234

235 236
      it { should be_allowed_for master }
      it { should be_allowed_for reporter }
Robert Speicher's avatar
Robert Speicher committed
237
      it { should be_denied_for :admin }
238
      it { should be_denied_for guest }
Robert Speicher's avatar
Robert Speicher committed
239 240
      it { should be_denied_for :user }
      it { should be_denied_for :visitor }
241
    end
gitlabhq's avatar
gitlabhq committed
242 243
  end
end