2016-11-28 02:43:53 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Profiles::PersonalAccessTokensController do
|
|
|
|
let(:user) { create(:user) }
|
2017-02-06 10:39:35 -05:00
|
|
|
let(:token_attributes) { attributes_for(:personal_access_token) }
|
2016-11-28 02:43:53 -05:00
|
|
|
|
2016-12-28 11:19:08 -05:00
|
|
|
before { sign_in(user) }
|
|
|
|
|
2016-11-28 02:43:53 -05:00
|
|
|
describe '#create' do
|
|
|
|
def created_token
|
|
|
|
PersonalAccessToken.order(:created_at).last
|
|
|
|
end
|
|
|
|
|
2017-02-06 10:39:35 -05:00
|
|
|
it "allows creation of a token with scopes" do
|
2017-03-23 09:08:39 -04:00
|
|
|
name = 'My PAT'
|
2017-02-06 10:39:35 -05:00
|
|
|
scopes = %w[api read_user]
|
2016-11-28 02:43:53 -05:00
|
|
|
|
2017-03-07 13:12:22 -05:00
|
|
|
post :create, personal_access_token: token_attributes.merge(scopes: scopes, name: name)
|
2016-11-28 02:43:53 -05:00
|
|
|
|
|
|
|
expect(created_token).not_to be_nil
|
2017-03-07 13:12:22 -05:00
|
|
|
expect(created_token.name).to eq(name)
|
2017-02-06 10:39:35 -05:00
|
|
|
expect(created_token.scopes).to eq(scopes)
|
2016-11-28 02:43:53 -05:00
|
|
|
expect(PersonalAccessToken.active).to include(created_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows creation of a token with an expiry date" do
|
2016-12-27 11:26:57 -05:00
|
|
|
expires_at = 5.days.from_now.to_date
|
2016-11-28 02:43:53 -05:00
|
|
|
|
2017-02-06 10:39:35 -05:00
|
|
|
post :create, personal_access_token: token_attributes.merge(expires_at: expires_at)
|
2016-11-28 02:43:53 -05:00
|
|
|
|
|
|
|
expect(created_token).not_to be_nil
|
2016-12-27 11:26:57 -05:00
|
|
|
expect(created_token.expires_at).to eq(expires_at)
|
2016-11-28 02:43:53 -05:00
|
|
|
end
|
|
|
|
end
|
2016-12-28 11:19:08 -05:00
|
|
|
|
|
|
|
describe '#index' do
|
|
|
|
let!(:active_personal_access_token) { create(:personal_access_token, user: user) }
|
2017-03-01 11:59:03 -05:00
|
|
|
let!(:inactive_personal_access_token) { create(:personal_access_token, :revoked, user: user) }
|
|
|
|
let!(:impersonation_personal_access_token) { create(:personal_access_token, :impersonation, user: user) }
|
2016-12-28 11:19:08 -05:00
|
|
|
|
2017-02-09 10:21:09 -05:00
|
|
|
before { get :index }
|
2016-12-28 11:19:08 -05:00
|
|
|
|
2017-02-09 10:21:09 -05:00
|
|
|
it "retrieves active personal access tokens" do
|
2016-12-28 11:19:08 -05:00
|
|
|
expect(assigns(:active_personal_access_tokens)).to include(active_personal_access_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "retrieves inactive personal access tokens" do
|
|
|
|
expect(assigns(:inactive_personal_access_tokens)).to include(inactive_personal_access_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not retrieve impersonation personal access tokens" do
|
|
|
|
expect(assigns(:active_personal_access_tokens)).not_to include(impersonation_personal_access_token)
|
|
|
|
expect(assigns(:inactive_personal_access_tokens)).not_to include(impersonation_personal_access_token)
|
|
|
|
end
|
|
|
|
end
|
2016-11-28 02:43:53 -05:00
|
|
|
end
|