2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe 'Admin > Users > Impersonation Tokens', js: true do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let!(:user) { create(:user) }
|
|
|
|
|
|
|
|
def active_impersonation_tokens
|
|
|
|
find(".table.active-tokens")
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def no_personal_access_tokens_message
|
|
|
|
find(".settings-message")
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe "token creation" do
|
|
|
|
it "allows creation of a token" do
|
|
|
|
name = 'Hello World'
|
|
|
|
|
|
|
|
visit admin_user_impersonation_tokens_path(user_id: user.username)
|
|
|
|
fill_in "Name", with: name
|
|
|
|
|
|
|
|
# Set date to 1st of next month
|
|
|
|
find_field("Expires at").trigger('focus')
|
|
|
|
find(".pika-next").click
|
|
|
|
click_on "1"
|
|
|
|
|
|
|
|
# Scopes
|
|
|
|
check "api"
|
|
|
|
check "read_user"
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
click_on "Create impersonation token"
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(active_impersonation_tokens).to have_text(name)
|
|
|
|
expect(active_impersonation_tokens).to have_text('In')
|
|
|
|
expect(active_impersonation_tokens).to have_text('api')
|
|
|
|
expect(active_impersonation_tokens).to have_text('read_user')
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(PersonalAccessTokensFinder.new(impersonation: true).execute.count).to equal(1)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'active tokens' do
|
|
|
|
let!(:impersonation_token) { create(:personal_access_token, :impersonation, user: user) }
|
|
|
|
let!(:personal_access_token) { create(:personal_access_token, user: user) }
|
|
|
|
|
|
|
|
it 'only shows impersonation tokens' do
|
|
|
|
visit admin_user_impersonation_tokens_path(user_id: user.username)
|
|
|
|
|
|
|
|
expect(active_impersonation_tokens).to have_text(impersonation_token.name)
|
|
|
|
expect(active_impersonation_tokens).not_to have_text(personal_access_token.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "inactive tokens" do
|
|
|
|
let!(:impersonation_token) { create(:personal_access_token, :impersonation, user: user) }
|
|
|
|
|
|
|
|
it "allows revocation of an active impersonation token" do
|
|
|
|
visit admin_user_impersonation_tokens_path(user_id: user.username)
|
|
|
|
|
|
|
|
click_on "Revoke"
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(page).to have_selector(".settings-message")
|
|
|
|
expect(no_personal_access_tokens_message).to have_text("This user has no active Impersonation Tokens.")
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it "removes expired tokens from 'active' section" do
|
2017-08-17 22:00:37 +05:30
|
|
|
impersonation_token.update(expires_at: 5.days.ago)
|
|
|
|
|
|
|
|
visit admin_user_impersonation_tokens_path(user_id: user.username)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(page).to have_selector(".settings-message")
|
|
|
|
expect(no_personal_access_tokens_message).to have_text("This user has no active Impersonation Tokens.")
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|