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
|
|
|
|
let_it_be(:current_user) { build(:admin) }
|
|
|
|
|
|
|
|
context 'not the owner of the token' do
|
|
|
|
let_it_be(:token) { build(:personal_access_token) }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:read_token) }
|
|
|
|
it { is_expected.to be_allowed(:revoke_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'owner of the token' do
|
|
|
|
let_it_be(:token) { build(:personal_access_token, user: current_user) }
|
|
|
|
|
|
|
|
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
|
|
|
|
let_it_be(:current_user) { build(: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
|
|
|
|
let_it_be(:token) { build(: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
|
|
|
|
let_it_be(:token) { build(: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-08-11 08:09:55 -04:00
|
|
|
let_it_be(:current_user) { build(:admin, :blocked) }
|
|
|
|
|
|
|
|
context 'owner of the token' do
|
|
|
|
let_it_be(:token) { build(: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
|
|
|
|
let_it_be(:token) { build(: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
|