debian-mirror-gitlab/spec/models/project_security_spec.rb

113 lines
3.4 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe Project, models: true do
2016-08-24 12:49:21 +05:30
describe 'authorization' do
2014-09-02 18:07:02 +05:30
before do
@p1 = create(:project)
@u1 = create(:user)
@u2 = create(:user)
@u3 = create(:user)
@u4 = @p1.owner
@abilities = Six.new
@abilities << Ability
end
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 }
2016-06-02 11:05:42 +05:30
let(:owner_actions) { Ability.project_owner_rules }
2014-09-02 18:07:02 +05:30
describe "Non member rules" do
2016-09-13 17:45:13 +05:30
it "denies for non-project users any actions" do
2016-06-02 11:05:42 +05:30
owner_actions.each do |action|
2015-04-26 12:48:37 +05:30
expect(@abilities.allowed?(@u1, action, @p1)).to be_falsey
2014-09-02 18:07:02 +05:30
end
end
end
describe "Guest Rules" do
before do
2015-04-26 12:48:37 +05:30
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::GUEST)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "allows for project user any guest actions" do
2014-09-02 18:07:02 +05:30
guest_actions.each do |action|
2015-04-26 12:48:37 +05:30
expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy
2014-09-02 18:07:02 +05:30
end
end
end
describe "Report Rules" do
before do
2015-04-26 12:48:37 +05:30
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::REPORTER)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "allows for project user any report actions" do
2014-09-02 18:07:02 +05:30
report_actions.each do |action|
2015-04-26 12:48:37 +05:30
expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy
2014-09-02 18:07:02 +05:30
end
end
end
describe "Developer Rules" do
before do
2015-04-26 12:48:37 +05:30
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::REPORTER)
@p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::DEVELOPER)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "denies for developer master-specific actions" do
2014-09-02 18:07:02 +05:30
[dev_actions - report_actions].each do |action|
2015-04-26 12:48:37 +05:30
expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
2014-09-02 18:07:02 +05:30
end
end
2016-09-13 17:45:13 +05:30
it "allows for project user any dev actions" do
2014-09-02 18:07:02 +05:30
dev_actions.each do |action|
2015-04-26 12:48:37 +05:30
expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy
2014-09-02 18:07:02 +05:30
end
end
end
describe "Master Rules" do
before do
2015-04-26 12:48:37 +05:30
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::DEVELOPER)
@p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "denies for developer master-specific actions" do
2014-09-02 18:07:02 +05:30
[master_actions - dev_actions].each do |action|
2015-04-26 12:48:37 +05:30
expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
2014-09-02 18:07:02 +05:30
end
end
2016-09-13 17:45:13 +05:30
it "allows for project user any master actions" do
2014-09-02 18:07:02 +05:30
master_actions.each do |action|
2015-04-26 12:48:37 +05:30
expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy
2014-09-02 18:07:02 +05:30
end
end
end
2016-06-02 11:05:42 +05:30
describe "Owner Rules" do
2014-09-02 18:07:02 +05:30
before do
2015-04-26 12:48:37 +05:30
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::DEVELOPER)
@p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "denies for masters admin-specific actions" do
2016-06-02 11:05:42 +05:30
[owner_actions - master_actions].each do |action|
2015-04-26 12:48:37 +05:30
expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
2014-09-02 18:07:02 +05:30
end
end
2016-09-13 17:45:13 +05:30
it "allows for project owner any admin actions" do
2016-06-02 11:05:42 +05:30
owner_actions.each do |action|
2015-04-26 12:48:37 +05:30
expect(@abilities.allowed?(@u4, action, @p1)).to be_truthy
2014-09-02 18:07:02 +05:30
end
end
end
end
end