debian-mirror-gitlab/spec/features/users/active_sessions_spec.rb

76 lines
2.2 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-10-15 14:42:47 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Active user sessions', :clean_gitlab_redis_sessions, feature_category: :system_access do
2021-02-22 17:27:13 +05:30
it 'successful login adds a new active user login' do
2023-03-04 22:38:38 +05:30
user = create(:user)
2018-10-15 14:42:47 +05:30
now = Time.zone.parse('2018-03-12 09:06')
2023-03-04 22:38:38 +05:30
travel_to(now) do
2018-10-15 14:42:47 +05:30
gitlab_sign_in(user)
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path root_path, ignore_query: true
2018-10-15 14:42:47 +05:30
sessions = ActiveSession.list(user)
expect(sessions.count).to eq 1
2023-03-04 22:38:38 +05:30
gitlab_sign_out
end
2018-10-15 14:42:47 +05:30
2023-03-04 22:38:38 +05:30
# refresh the current page updates the updated_at
travel_to(now + 1.minute) do
gitlab_sign_in(user)
visit current_path
2018-10-15 14:42:47 +05:30
2023-03-04 22:38:38 +05:30
sessions = ActiveSession.list(user)
expect(sessions.first).to have_attributes(
created_at: Time.zone.parse('2018-03-12 09:06'),
updated_at: Time.zone.parse('2018-03-12 09:07')
)
2018-10-15 14:42:47 +05:30
end
end
2021-02-22 17:27:13 +05:30
it 'successful login cleans up obsolete entries' do
2018-10-15 14:42:47 +05:30
user = create(:user)
2022-01-26 12:08:38 +05:30
Gitlab::Redis::Sessions.with do |redis|
2023-01-13 00:05:48 +05:30
redis.sadd?("session:lookup:user:gitlab:#{user.id}", '59822c7d9fcdfa03725eff41782ad97d')
2018-10-15 14:42:47 +05:30
end
gitlab_sign_in(user)
2022-01-26 12:08:38 +05:30
Gitlab::Redis::Sessions.with do |redis|
2018-10-15 14:42:47 +05:30
expect(redis.smembers("session:lookup:user:gitlab:#{user.id}")).not_to include '59822c7d9fcdfa03725eff41782ad97d'
end
end
2021-02-22 17:27:13 +05:30
it 'sessionless login does not clean up obsolete entries' do
2018-10-15 14:42:47 +05:30
user = create(:user)
personal_access_token = create(:personal_access_token, user: user)
2022-01-26 12:08:38 +05:30
Gitlab::Redis::Sessions.with do |redis|
2023-01-13 00:05:48 +05:30
redis.sadd?("session:lookup:user:gitlab:#{user.id}", '59822c7d9fcdfa03725eff41782ad97d')
2018-10-15 14:42:47 +05:30
end
visit user_path(user, :atom, private_token: personal_access_token.token)
expect(page.status_code).to eq 200
2022-01-26 12:08:38 +05:30
Gitlab::Redis::Sessions.with do |redis|
2018-10-15 14:42:47 +05:30
expect(redis.smembers("session:lookup:user:gitlab:#{user.id}")).to include '59822c7d9fcdfa03725eff41782ad97d'
end
end
2021-02-22 17:27:13 +05:30
it 'logout deletes the active user login' do
2018-10-15 14:42:47 +05:30
user = create(:user)
gitlab_sign_in(user)
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path root_path, ignore_query: true
2018-10-15 14:42:47 +05:30
expect(ActiveSession.list(user).count).to eq 1
gitlab_sign_out
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path new_user_session_path, ignore_query: true
2018-10-15 14:42:47 +05:30
expect(ActiveSession.list(user)).to be_empty
end
end