2020-04-30 08:09:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-11-24 13:14:31 -05:00
|
|
|
RSpec.describe ApplicationCable::Connection, :clean_gitlab_redis_sessions do
|
2022-02-03 10:12:41 -05:00
|
|
|
include SessionHelpers
|
2020-04-30 08:09:45 -04:00
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
context 'when session cookie is set' do
|
|
|
|
before do
|
2022-02-03 10:12:41 -05:00
|
|
|
stub_session(session_hash)
|
2020-04-30 08:09:45 -04:00
|
|
|
end
|
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
context 'when user is logged in' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:session_hash) { { 'warden.user.user.key' => [[user.id], user.encrypted_password[0, 29]] } }
|
|
|
|
|
|
|
|
it 'sets current_user' do
|
|
|
|
connect
|
|
|
|
|
|
|
|
expect(connection.current_user).to eq(user)
|
|
|
|
end
|
2020-04-30 08:09:45 -04:00
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
context 'with a stale password' do
|
|
|
|
let(:partial_password_hash) { build(:user, password: 'some_old_password').encrypted_password[0, 29] }
|
|
|
|
let(:session_hash) { { 'warden.user.user.key' => [[user.id], partial_password_hash] } }
|
2020-04-30 08:09:45 -04:00
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
it 'sets current_user to nil' do
|
|
|
|
connect
|
2020-04-30 08:09:45 -04:00
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
expect(connection.current_user).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2020-04-30 08:09:45 -04:00
|
|
|
end
|
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
context 'when user is not logged in' do
|
|
|
|
let(:session_hash) { {} }
|
2020-04-30 08:09:45 -04:00
|
|
|
|
|
|
|
it 'sets current_user to nil' do
|
|
|
|
connect
|
|
|
|
|
|
|
|
expect(connection.current_user).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
context 'when session cookie is not set' do
|
|
|
|
it 'sets current_user to nil' do
|
|
|
|
connect
|
|
|
|
|
|
|
|
expect(connection.current_user).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2020-04-30 08:09:45 -04:00
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
context 'when session cookie is an empty string' do
|
2020-04-30 08:09:45 -04:00
|
|
|
it 'sets current_user to nil' do
|
2020-10-02 08:09:03 -04:00
|
|
|
cookies[Gitlab::Application.config.session_options[:key]] = ''
|
|
|
|
|
2020-04-30 08:09:45 -04:00
|
|
|
connect
|
|
|
|
|
|
|
|
expect(connection.current_user).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|