debian-mirror-gitlab/spec/policies/deploy_key_policy_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
2.1 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe DeployKeyPolicy do
2017-09-10 17:25:29 +05:30
subject { described_class.new(current_user, deploy_key) }
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-11-18 11:00:15 +05:30
project.add_maintainer(current_user)
2017-09-10 17:25:29 +05:30
project.deploy_keys << deploy_key
end
it { is_expected.to be_allowed(:update_deploy_key) }
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
it { is_expected.to be_disallowed(:update_deploy_key) }
end
context 'tries to update public deploy key' do
let(:deploy_key) { create(:another_deploy_key, public: true) }
it { is_expected.to be_disallowed(:update_deploy_key) }
end
end
context 'when an admin user' do
let(:current_user) { create(:user, :admin) }
2020-05-24 23:13:21 +05:30
context 'tries to update private deploy key' do
2017-09-10 17:25:29 +05:30
let(:deploy_key) { create(:deploy_key, public: false) }
2020-05-24 23:13:21 +05:30
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-09-10 17:25:29 +05:30
end
context 'when an admin user tries to update public deploy key' do
let(:deploy_key) { create(:another_deploy_key, public: true) }
2020-05-24 23:13:21 +05:30
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-09-10 17:25:29 +05:30
end
end
end
end