BigW Consortium Gitlab

private_access_spec.rb 6.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
require 'spec_helper'

describe "Private Project Access" do
  let(:project) { create(:project_with_code) }

  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 "GET /:project_path" do
    subject { project_path(project) }

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_denied_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

  describe "GET /:project_path/wall" do
    subject { project_wall_path(project) }

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

  describe "GET /:project_path/blob" do
    before do
      commit = project.repository.commit
      path = commit.tree.contents.select { |i| i.is_a?(Grit::Blob) }.first.name
      @blob_path = project_blob_path(project, File.join(commit.id, path))
    end

    it { @blob_path.should be_allowed_for master }
    it { @blob_path.should be_allowed_for reporter }
    it { @blob_path.should be_allowed_for :admin }
    it { @blob_path.should be_denied_for guest }
    it { @blob_path.should be_denied_for :user }
    it { @blob_path.should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_denied_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_denied_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    before do
      # Speed increase
      Project.any_instance.stub(:branches).and_return([])
    end

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    before do
      # Speed increase
      Project.any_instance.stub(:tags).and_return([])
    end

    it { should be_allowed_for master }
    it { should be_allowed_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end

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

    it { should be_allowed_for master }
    it { should be_denied_for reporter }
    it { should be_allowed_for :admin }
    it { should be_denied_for guest }
    it { should be_denied_for :user }
    it { should be_denied_for :visitor }
  end
end