2019-10-24 20:06:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-31 08:54:38 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe DeployKeyPolicy 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
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(current_user)
|
2017-03-31 08:54:38 -04:00
|
|
|
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) }
|
|
|
|
|
2020-05-15 11:08:04 -04:00
|
|
|
context 'tries to update private deploy key' do
|
2017-03-31 08:54:38 -04:00
|
|
|
let(:deploy_key) { create(:deploy_key, public: false) }
|
|
|
|
|
2020-05-15 11:08:04 -04:00
|
|
|
context 'when admin mode enabled', :enable_admin_mode do
|
|
|
|
it { is_expected.to be_allowed(:update_deploy_key) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode disabled' do
|
|
|
|
it { is_expected.to be_disallowed(:update_deploy_key) }
|
|
|
|
end
|
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) }
|
|
|
|
|
2020-05-15 11:08:04 -04:00
|
|
|
context 'when admin mode enabled', :enable_admin_mode do
|
|
|
|
it { is_expected.to be_allowed(:update_deploy_key) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode disabled' do
|
|
|
|
it { is_expected.to be_disallowed(:update_deploy_key) }
|
|
|
|
end
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|