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

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

71 lines
2.2 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe PersonalAccessTokenPolicy do
include AdminModeHelper
subject { described_class.new(current_user, token) }
context 'current_user is an administrator', :enable_admin_mode do
2020-11-24 15:15:51 +05:30
let_it_be(:current_user) { build_stubbed(:admin) }
2020-10-24 23:57:45 +05:30
context 'not the owner of the token' do
2020-11-24 15:15:51 +05:30
let_it_be(:token) { build_stubbed(:personal_access_token) }
2020-10-24 23:57:45 +05:30
it { is_expected.to be_allowed(:read_token) }
it { is_expected.to be_allowed(:revoke_token) }
end
context 'owner of the token' do
2020-11-24 15:15:51 +05:30
let_it_be(:token) { build_stubbed(:personal_access_token, user: current_user) }
2020-10-24 23:57:45 +05:30
it { is_expected.to be_allowed(:read_token) }
it { is_expected.to be_allowed(:revoke_token) }
end
end
context 'current_user is not an administrator' do
2020-11-24 15:15:51 +05:30
let_it_be(:current_user) { build_stubbed(:user) }
2020-10-24 23:57:45 +05:30
context 'not the owner of the token' do
2020-11-24 15:15:51 +05:30
let_it_be(:token) { build_stubbed(:personal_access_token) }
2020-10-24 23:57:45 +05:30
it { is_expected.to be_disallowed(:read_token) }
it { is_expected.to be_disallowed(:revoke_token) }
end
context 'owner of the token' do
2020-11-24 15:15:51 +05:30
let_it_be(:token) { build_stubbed(:personal_access_token, user: current_user) }
2020-10-24 23:57:45 +05:30
it { is_expected.to be_allowed(:read_token) }
it { is_expected.to be_allowed(:revoke_token) }
end
2021-08-04 16:29:09 +05:30
context 'subject of the impersonated token' do
let_it_be(:token) { build_stubbed(:personal_access_token, user: current_user, impersonation: true) }
it { is_expected.to be_disallowed(:read_token) }
it { is_expected.to be_disallowed(:revoke_token) }
end
2020-10-24 23:57:45 +05:30
end
context 'current_user is a blocked administrator', :enable_admin_mode do
2020-11-24 15:15:51 +05:30
let_it_be(:current_user) { create(:admin, :blocked) }
2020-10-24 23:57:45 +05:30
context 'owner of the token' do
2020-11-24 15:15:51 +05:30
let_it_be(:token) { build_stubbed(:personal_access_token, user: current_user) }
2020-10-24 23:57:45 +05:30
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-11-24 15:15:51 +05:30
let_it_be(:token) { build_stubbed(:personal_access_token) }
2020-10-24 23:57:45 +05:30
it { is_expected.to be_disallowed(:read_token) }
it { is_expected.to be_disallowed(:revoke_token) }
end
end
end