2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2018-05-02 04:08:16 -04:00
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Profile > Active Sessions', :clean_gitlab_redis_shared_state do
|
2018-05-02 04:08:16 -04:00
|
|
|
let(:user) do
|
|
|
|
create(:user).tap do |user|
|
|
|
|
user.current_sign_in_at = Time.current
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-23 13:18:44 -05:00
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
|
2021-11-11 07:10:41 -05:00
|
|
|
before do
|
|
|
|
stub_feature_flags(bootstrap_confirmation_modals: false)
|
|
|
|
end
|
|
|
|
|
2020-12-09 13:09:48 -05:00
|
|
|
it 'user sees their active sessions' do
|
2020-12-01 10:09:28 -05:00
|
|
|
travel_to(Time.zone.parse('2018-03-12 09:06')) do
|
2020-02-26 04:08:47 -05:00
|
|
|
Capybara::Session.new(:session1)
|
|
|
|
Capybara::Session.new(:session2)
|
|
|
|
Capybara::Session.new(:session3)
|
|
|
|
|
|
|
|
# note: headers can only be set on the non-js (aka. rack-test) driver
|
|
|
|
using_session :session1 do
|
|
|
|
Capybara.page.driver.header(
|
|
|
|
'User-Agent',
|
|
|
|
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0'
|
|
|
|
)
|
|
|
|
|
|
|
|
gitlab_sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
# set an additional session on another device
|
|
|
|
using_session :session2 do
|
|
|
|
Capybara.page.driver.header(
|
|
|
|
'User-Agent',
|
|
|
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B466 [FBDV/iPhone7,2]'
|
|
|
|
)
|
|
|
|
|
|
|
|
gitlab_sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
# set an admin session impersonating the user
|
|
|
|
using_session :session3 do
|
|
|
|
Capybara.page.driver.header(
|
|
|
|
'User-Agent',
|
|
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'
|
|
|
|
)
|
|
|
|
|
|
|
|
gitlab_sign_in(admin)
|
2020-11-23 10:09:37 -05:00
|
|
|
gitlab_enable_admin_mode_sign_in(admin)
|
2020-02-26 04:08:47 -05:00
|
|
|
|
|
|
|
visit admin_user_path(user)
|
|
|
|
|
|
|
|
click_link 'Impersonate'
|
|
|
|
end
|
|
|
|
|
|
|
|
using_session :session1 do
|
|
|
|
visit profile_active_sessions_path
|
|
|
|
|
|
|
|
expect(page).to(
|
2020-11-24 04:09:32 -05:00
|
|
|
have_selector('ul.list-group li.list-group-item', text: 'Signed in on',
|
|
|
|
count: 2))
|
2020-02-26 04:08:47 -05:00
|
|
|
|
|
|
|
expect(page).to have_content(
|
|
|
|
'127.0.0.1 ' \
|
|
|
|
'This is your current session ' \
|
|
|
|
'Firefox on Ubuntu ' \
|
|
|
|
'Signed in on 12 Mar 09:06'
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(page).to have_selector '[title="Desktop"]', count: 1
|
|
|
|
|
|
|
|
expect(page).to have_content(
|
|
|
|
'127.0.0.1 ' \
|
|
|
|
'Last accessed on 12 Mar 09:06 ' \
|
|
|
|
'Mobile Safari on iOS ' \
|
|
|
|
'Signed in on 12 Mar 09:06'
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(page).to have_selector '[title="Smartphone"]', count: 1
|
|
|
|
|
|
|
|
expect(page).not_to have_content('Chrome on Windows')
|
|
|
|
end
|
2018-05-02 04:08:16 -04:00
|
|
|
end
|
|
|
|
end
|
2020-01-03 04:07:33 -05:00
|
|
|
|
2020-12-09 13:09:48 -05:00
|
|
|
it 'user can revoke a session', :js do
|
2020-01-03 04:07:33 -05:00
|
|
|
Capybara::Session.new(:session1)
|
|
|
|
Capybara::Session.new(:session2)
|
|
|
|
|
|
|
|
# set an additional session in another browser
|
|
|
|
using_session :session2 do
|
|
|
|
gitlab_sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
using_session :session1 do
|
|
|
|
gitlab_sign_in(user)
|
|
|
|
visit profile_active_sessions_path
|
|
|
|
|
|
|
|
expect(page).to have_link('Revoke', count: 1)
|
|
|
|
|
|
|
|
accept_confirm { click_on 'Revoke' }
|
|
|
|
|
|
|
|
expect(page).not_to have_link('Revoke')
|
|
|
|
end
|
|
|
|
|
|
|
|
using_session :session2 do
|
|
|
|
visit profile_active_sessions_path
|
|
|
|
|
|
|
|
expect(page).to have_content('You need to sign in or sign up before continuing.')
|
|
|
|
end
|
|
|
|
end
|
2018-05-02 04:08:16 -04:00
|
|
|
end
|