debian-mirror-gitlab/spec/features/admin/admin_users_impersonation_tokens_spec.rb

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

96 lines
3 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Admin > Users > Impersonation Tokens', :js, feature_category: :authentication_and_authorization do
2022-07-23 23:45:48 +05:30
include Spec::Support::Helpers::ModalHelpers
2023-01-13 00:05:48 +05:30
include Spec::Support::Helpers::AccessTokenHelpers
2022-07-23 23:45:48 +05:30
2017-08-17 22:00:37 +05:30
let(:admin) { create(:admin) }
let!(:user) { create(:user) }
2017-09-10 17:25:29 +05:30
before do
sign_in(admin)
2021-02-22 17:27:13 +05:30
gitlab_enable_admin_mode_sign_in(admin)
2017-09-10 17:25:29 +05:30
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)
2021-09-30 23:02:18 +05:30
fill_in "Token name", with: name
2017-08-17 22:00:37 +05:30
# Set date to 1st of next month
2021-09-30 23:02:18 +05:30
find_field("Expiration date").click
2017-08-17 22:00:37 +05:30
find(".pika-next").click
click_on "1"
# Scopes
2022-06-21 17:19:12 +05:30
check "read_api"
2017-08-17 22:00:37 +05:30
check "read_user"
2017-09-10 17:25:29 +05:30
click_on "Create impersonation token"
2023-01-13 00:05:48 +05:30
expect(active_access_tokens).to have_text(name)
expect(active_access_tokens).to have_text('in')
expect(active_access_tokens).to have_text('read_api')
expect(active_access_tokens).to have_text('read_user')
2017-09-10 17:25:29 +05:30
expect(PersonalAccessTokensFinder.new(impersonation: true).execute.count).to equal(1)
2023-01-13 00:05:48 +05:30
expect(created_access_token).to match(/[\w-]{20}/)
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)
2023-01-13 00:05:48 +05:30
expect(active_access_tokens).to have_text(impersonation_token.name)
expect(active_access_tokens).not_to have_text(personal_access_token.name)
expect(active_access_tokens).to have_text('in')
2021-11-11 11:23:49 +05:30
end
it 'shows absolute times' do
admin.update!(time_display_relative: false)
visit admin_user_impersonation_tokens_path(user_id: user.username)
2023-01-13 00:05:48 +05:30
expect(active_access_tokens).to have_text(personal_access_token.expires_at.strftime('%b %-d'))
2017-08-17 22:00:37 +05:30
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)
2022-07-23 23:45:48 +05:30
accept_gl_confirm(button_text: 'Revoke') { click_on "Revoke" }
2017-08-17 22:00:37 +05:30
2023-01-13 00:05:48 +05:30
expect(active_access_tokens).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
2021-04-29 21:17:54 +05:30
impersonation_token.update!(expires_at: 5.days.ago)
2017-08-17 22:00:37 +05:30
visit admin_user_impersonation_tokens_path(user_id: user.username)
2023-01-13 00:05:48 +05:30
expect(active_access_tokens).to have_text("This user has no active impersonation tokens.")
2017-08-17 22:00:37 +05:30
end
end
2021-08-04 16:29:09 +05:30
describe "impersonation disabled state" do
before do
stub_config_setting(impersonation_enabled: false)
end
it "does not show impersonation tokens tab" do
visit admin_user_path(user)
expect(page).not_to have_content("Impersonation Tokens")
end
end
2017-08-17 22:00:37 +05:30
end