2019-10-16 05:07:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-27 13:56:54 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe PersonalAccessTokensFinder do
|
2017-03-01 11:59:03 -05:00
|
|
|
def finder(options = {})
|
|
|
|
described_class.new(options)
|
|
|
|
end
|
|
|
|
|
2017-02-27 13:56:54 -05:00
|
|
|
describe '#execute' do
|
|
|
|
let(:user) { create(:user) }
|
2017-03-01 11:59:03 -05:00
|
|
|
let(:params) { {} }
|
2017-02-27 13:56:54 -05:00
|
|
|
let!(:active_personal_access_token) { create(:personal_access_token, user: user) }
|
2017-03-01 11:59:03 -05:00
|
|
|
let!(:expired_personal_access_token) { create(:personal_access_token, :expired, user: user) }
|
|
|
|
let!(:revoked_personal_access_token) { create(:personal_access_token, :revoked, user: user) }
|
|
|
|
let!(:active_impersonation_token) { create(:personal_access_token, :impersonation, user: user) }
|
|
|
|
let!(:expired_impersonation_token) { create(:personal_access_token, :expired, :impersonation, user: user) }
|
|
|
|
let!(:revoked_impersonation_token) { create(:personal_access_token, :revoked, :impersonation, user: user) }
|
2017-02-27 13:56:54 -05:00
|
|
|
|
2017-03-01 11:59:03 -05:00
|
|
|
subject { finder(params).execute }
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
describe 'without user' do
|
|
|
|
it do
|
|
|
|
is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token,
|
|
|
|
revoked_personal_access_token, expired_personal_access_token,
|
|
|
|
revoked_impersonation_token, expired_impersonation_token)
|
|
|
|
end
|
|
|
|
|
2019-12-17 04:07:48 -05:00
|
|
|
describe 'with sort order' do
|
|
|
|
before do
|
|
|
|
params[:sort] = 'id_asc'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts records as per the specified sort order' do
|
|
|
|
expect(subject).to match_array(PersonalAccessToken.all.order(id: :asc))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-27 13:56:54 -05:00
|
|
|
describe 'without impersonation' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:impersonation] = false
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(active_personal_access_token, revoked_personal_access_token, expired_personal_access_token) }
|
|
|
|
|
|
|
|
describe 'with active state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'active'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(active_personal_access_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with inactive state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'inactive'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(revoked_personal_access_token, expired_personal_access_token) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with impersonation' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:impersonation] = true
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(active_impersonation_token, revoked_impersonation_token, expired_impersonation_token) }
|
|
|
|
|
|
|
|
describe 'with active state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'active'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(active_impersonation_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with inactive state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'inactive'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(revoked_impersonation_token, expired_impersonation_token) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with active state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'active'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with inactive state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'inactive'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to contain_exactly(expired_personal_access_token, revoked_personal_access_token,
|
|
|
|
expired_impersonation_token, revoked_impersonation_token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with id' do
|
2018-10-26 10:47:03 -04:00
|
|
|
subject { finder(params).find_by_id(active_personal_access_token.id) }
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to eq(active_personal_access_token) }
|
|
|
|
|
|
|
|
describe 'with impersonation' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:impersonation] = true
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with token' do
|
2018-10-26 10:47:03 -04:00
|
|
|
subject { finder(params).find_by_token(active_personal_access_token.token) }
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to eq(active_personal_access_token) }
|
|
|
|
|
|
|
|
describe 'with impersonation' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:impersonation] = true
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with user' do
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let!(:other_user_active_personal_access_token) { create(:personal_access_token, user: user2) }
|
2017-03-01 11:59:03 -05:00
|
|
|
let!(:other_user_expired_personal_access_token) { create(:personal_access_token, :expired, user: user2) }
|
|
|
|
let!(:other_user_revoked_personal_access_token) { create(:personal_access_token, :revoked, user: user2) }
|
|
|
|
let!(:other_user_active_impersonation_token) { create(:personal_access_token, :impersonation, user: user2) }
|
|
|
|
let!(:other_user_expired_impersonation_token) { create(:personal_access_token, :expired, :impersonation, user: user2) }
|
|
|
|
let!(:other_user_revoked_impersonation_token) { create(:personal_access_token, :revoked, :impersonation, user: user2) }
|
|
|
|
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:user] = user
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token,
|
|
|
|
revoked_personal_access_token, expired_personal_access_token,
|
|
|
|
revoked_impersonation_token, expired_impersonation_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'without impersonation' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:impersonation] = false
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(active_personal_access_token, revoked_personal_access_token, expired_personal_access_token) }
|
|
|
|
|
|
|
|
describe 'with active state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'active'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(active_personal_access_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with inactive state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'inactive'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(revoked_personal_access_token, expired_personal_access_token) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with impersonation' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:impersonation] = true
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(active_impersonation_token, revoked_impersonation_token, expired_impersonation_token) }
|
|
|
|
|
|
|
|
describe 'with active state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'active'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(active_impersonation_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with inactive state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'inactive'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(revoked_impersonation_token, expired_impersonation_token) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with active state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'active'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with inactive state' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:state] = 'inactive'
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to contain_exactly(expired_personal_access_token, revoked_personal_access_token,
|
|
|
|
expired_impersonation_token, revoked_impersonation_token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with id' do
|
2018-10-26 10:47:03 -04:00
|
|
|
subject { finder(params).find_by_id(active_personal_access_token.id) }
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to eq(active_personal_access_token) }
|
|
|
|
|
|
|
|
describe 'with impersonation' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:impersonation] = true
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with token' do
|
2018-10-26 10:47:03 -04:00
|
|
|
subject { finder(params).find_by_token(active_personal_access_token.token) }
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to eq(active_personal_access_token) }
|
|
|
|
|
|
|
|
describe 'with impersonation' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
params[:impersonation] = true
|
|
|
|
end
|
2017-02-27 13:56:54 -05:00
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|