2017-03-31 08:54:38 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe DeployKeyPolicy, models: true do
|
2017-04-06 17:09:58 -04:00
|
|
|
subject { described_class.new(current_user, deploy_key) }
|
2017-03-31 08:54:38 -04:00
|
|
|
|
|
|
|
describe 'updating a deploy_key' do
|
|
|
|
context 'when a regular user' do
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
context 'tries to update private deploy key attached to project' do
|
|
|
|
let(:deploy_key) { create(:deploy_key, public: false) }
|
|
|
|
let(:project) { create(:project_empty_repo) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_master(current_user)
|
|
|
|
project.deploy_keys << deploy_key
|
|
|
|
end
|
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
it { is_expected.to be_allowed(:update_deploy_key) }
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'tries to update private deploy key attached to other project' do
|
|
|
|
let(:deploy_key) { create(:deploy_key, public: false) }
|
|
|
|
let(:other_project) { create(:project_empty_repo) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
other_project.deploy_keys << deploy_key
|
|
|
|
end
|
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
it { is_expected.to be_disallowed(:update_deploy_key) }
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'tries to update public deploy key' do
|
|
|
|
let(:deploy_key) { create(:another_deploy_key, public: true) }
|
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
it { is_expected.to be_disallowed(:update_deploy_key) }
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an admin user' do
|
|
|
|
let(:current_user) { create(:user, :admin) }
|
|
|
|
|
|
|
|
context ' tries to update private deploy key' do
|
|
|
|
let(:deploy_key) { create(:deploy_key, public: false) }
|
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
it { is_expected.to be_allowed(:update_deploy_key) }
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an admin user tries to update public deploy key' do
|
|
|
|
let(:deploy_key) { create(:another_deploy_key, public: true) }
|
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
it { is_expected.to be_allowed(:update_deploy_key) }
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|