2020-07-29 11:09:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe PersonalAccessTokenPolicy do
|
|
|
|
include AdminModeHelper
|
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
subject { described_class.new(current_user, token) }
|
2020-07-29 11:09:39 -04:00
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
context 'current_user is an administrator', :enable_admin_mode do
|
2020-09-09 02:08:55 -04:00
|
|
|
let_it_be(:current_user) { build_stubbed(:admin) }
|
2020-08-11 08:09:55 -04:00
|
|
|
|
|
|
|
context 'not the owner of the token' do
|
2020-09-09 02:08:55 -04:00
|
|
|
let_it_be(:token) { build_stubbed(:personal_access_token) }
|
2020-08-11 08:09:55 -04:00
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_token) }
|
|
|
|
it { is_expected.to be_allowed(:revoke_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'owner of the token' do
|
2020-09-09 02:08:55 -04:00
|
|
|
let_it_be(:token) { build_stubbed(:personal_access_token, user: current_user) }
|
2020-08-11 08:09:55 -04:00
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_token) }
|
|
|
|
it { is_expected.to be_allowed(:revoke_token) }
|
|
|
|
end
|
2020-07-29 11:09:39 -04:00
|
|
|
end
|
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
context 'current_user is not an administrator' do
|
2020-09-09 02:08:55 -04:00
|
|
|
let_it_be(:current_user) { build_stubbed(:user) }
|
2020-07-29 11:09:39 -04:00
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
context 'not the owner of the token' do
|
2020-09-09 02:08:55 -04:00
|
|
|
let_it_be(:token) { build_stubbed(:personal_access_token) }
|
2020-07-29 11:09:39 -04:00
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
it { is_expected.to be_disallowed(:read_token) }
|
|
|
|
it { is_expected.to be_disallowed(:revoke_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'owner of the token' do
|
2020-09-09 02:08:55 -04:00
|
|
|
let_it_be(:token) { build_stubbed(:personal_access_token, user: current_user) }
|
2020-07-29 11:09:39 -04:00
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
it { is_expected.to be_allowed(:read_token) }
|
|
|
|
it { is_expected.to be_allowed(:revoke_token) }
|
2020-07-29 11:09:39 -04:00
|
|
|
end
|
|
|
|
end
|
2020-08-07 11:10:17 -04:00
|
|
|
|
|
|
|
context 'current_user is a blocked administrator', :enable_admin_mode do
|
2020-09-09 02:08:55 -04:00
|
|
|
let_it_be(:current_user) { create(:admin, :blocked) }
|
2020-08-11 08:09:55 -04:00
|
|
|
|
|
|
|
context 'owner of the token' do
|
2020-09-09 02:08:55 -04:00
|
|
|
let_it_be(:token) { build_stubbed(:personal_access_token, user: current_user) }
|
2020-08-07 11:10:17 -04:00
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
it { is_expected.to be_disallowed(:read_token) }
|
|
|
|
it { is_expected.to be_disallowed(:revoke_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not the owner of the token' do
|
2020-09-09 02:08:55 -04:00
|
|
|
let_it_be(:token) { build_stubbed(:personal_access_token) }
|
2020-08-07 11:10:17 -04:00
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
it { is_expected.to be_disallowed(:read_token) }
|
|
|
|
it { is_expected.to be_disallowed(:revoke_token) }
|
|
|
|
end
|
2020-08-07 11:10:17 -04:00
|
|
|
end
|
2020-07-29 11:09:39 -04:00
|
|
|
end
|