BigW Consortium Gitlab

project_security_spec.rb 3.46 KB
Newer Older
gitlabhq committed
1 2
require 'spec_helper'

Douwe Maan committed
3
describe Project, models: true do
Nihad Abbasov committed
4 5
  describe :authorization do
    before do
6
      @p1 = create(:project)
7

8 9
      @u1 = create(:user)
      @u2 = create(:user)
10
      @u3 = create(:user)
11
      @u4 = @p1.owner
12

gitlabhq committed
13 14 15 16
      @abilities = Six.new
      @abilities << Ability
    end

17 18 19 20 21 22 23 24 25
    let(:guest_actions) { Ability.project_guest_rules }
    let(:report_actions) { Ability.project_report_rules }
    let(:dev_actions) { Ability.project_dev_rules }
    let(:master_actions) { Ability.project_master_rules }
    let(:admin_actions) { Ability.project_admin_rules }

    describe "Non member rules" do
      it "should deny for non-project users any actions" do
        admin_actions.each do |action|
26
          expect(@abilities.allowed?(@u1, action, @p1)).to be_falsey
27 28 29 30 31 32
        end
      end
    end

    describe "Guest Rules" do
      before do
33
        @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::GUEST)
34 35 36 37
      end

      it "should allow for project user any guest actions" do
        guest_actions.each do |action|
38
          expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy
39 40 41 42 43
        end
      end
    end

    describe "Report Rules" do
Nihad Abbasov committed
44
      before do
45
        @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::REPORTER)
gitlabhq committed
46 47
      end

48 49
      it "should allow for project user any report actions" do
        report_actions.each do |action|
50
          expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy
51 52
        end
      end
gitlabhq committed
53 54
    end

55 56
    describe "Developer Rules" do
      before do
57 58
        @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::REPORTER)
        @p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::DEVELOPER)
59 60 61 62
      end

      it "should deny for developer master-specific actions" do
        [dev_actions - report_actions].each do |action|
63
          expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
64 65 66 67 68
        end
      end

      it "should allow for project user any dev actions" do
        dev_actions.each do |action|
69
          expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy
70 71 72 73 74
        end
      end
    end

    describe "Master Rules" do
Nihad Abbasov committed
75
      before do
76 77
        @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::DEVELOPER)
        @p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER)
gitlabhq committed
78 79
      end

80 81
      it "should deny for developer master-specific actions" do
        [master_actions - dev_actions].each do |action|
82
          expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
83 84 85 86 87
        end
      end

      it "should allow for project user any master actions" do
        master_actions.each do |action|
88
          expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy
89 90
        end
      end
gitlabhq committed
91 92
    end

93
    describe "Admin Rules" do
Nihad Abbasov committed
94
      before do
95 96
        @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::DEVELOPER)
        @p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER)
gitlabhq committed
97 98
      end

99 100
      it "should deny for masters admin-specific actions" do
        [admin_actions - master_actions].each do |action|
101
          expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
102 103 104 105 106
        end
      end

      it "should allow for project owner any admin actions" do
        admin_actions.each do |action|
107
          expect(@abilities.allowed?(@u4, action, @p1)).to be_truthy
108 109
        end
      end
gitlabhq committed
110 111 112
    end
  end
end