internal_access_spec.rb 7.92 KB
Newer Older
1 2
require 'spec_helper'

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

  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

  describe "Project should be internal" do
    subject { project }

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

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

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_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_denied_for :visitor }
36 37 38
  end

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

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_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_denied_for :visitor }
47 48 49
  end

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

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_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_denied_for :visitor }
58 59 60
  end

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

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_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_denied_for :visitor }
69 70 71
  end

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

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_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_denied_for :visitor }
80 81 82
  end

  describe "GET /:project_path/team" do
Vinnie Okada's avatar
Vinnie Okada committed
83
    subject { namespace_project_team_index_path(project.namespace, project) }
84

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's avatar
Dmitriy Zaporozhets committed
96
      path = '.gitignore'
Vinnie Okada's avatar
Vinnie Okada committed
97
      @blob_path = namespace_project_blob_path(project.namespace, project, File.join(commit.id, path))
98 99
    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_allowed_for guest }
    it { expect(@blob_path).to be_allowed_for :user }
    it { expect(@blob_path).to be_denied_for :visitor }
106 107 108
  end

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

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
  end

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

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
  end

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

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_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_denied_for :visitor }
139 140 141
  end

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

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_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_denied_for :visitor }
150 151 152
  end

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

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
  end

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

166 167 168 169 170 171
    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_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_denied_for :visitor }
172 173 174
  end

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

177 178 179 180 181 182
    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 }
183 184 185
  end

  describe "GET /:project_path/branches" do
Vinnie Okada's avatar
Vinnie Okada committed
186
    subject { namespace_project_branches_path(project.namespace, project) }
187 188 189

    before do
      # Speed increase
190
      allow_any_instance_of(Project).to receive(:branches).and_return([])
191 192
    end

193 194 195 196 197 198
    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_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_denied_for :visitor }
199 200 201
  end

  describe "GET /:project_path/tags" do
Vinnie Okada's avatar
Vinnie Okada committed
202
    subject { namespace_project_tags_path(project.namespace, project) }
203 204 205

    before do
      # Speed increase
206
      allow_any_instance_of(Project).to receive(:tags).and_return([])
207 208
    end

209 210 211 212 213 214
    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_allowed_for guest }
    it { is_expected.to be_allowed_for :user }
    it { is_expected.to be_denied_for :visitor }
215 216 217
  end

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

220 221 222 223 224 225
    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 }
226 227
  end
end