debian-mirror-gitlab/spec/channels/application_cable/connection_spec.rb

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

64 lines
1.5 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require 'spec_helper'
2022-01-26 12:08:38 +05:30
RSpec.describe ApplicationCable::Connection, :clean_gitlab_redis_sessions do
2022-04-04 11:22:00 +05:30
include SessionHelpers
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
context 'when session cookie is set' do
before do
2022-04-04 11:22:00 +05:30
stub_session(session_hash)
2020-05-24 23:13:21 +05:30
end
2021-01-03 14:25:43 +05:30
context 'when user is logged in' do
let(:user) { create(:user) }
2022-08-13 15:12:31 +05:30
let(:session_hash) { { 'warden.user.user.key' => [[user.id], user.authenticatable_salt] } }
2021-01-03 14:25:43 +05:30
it 'sets current_user' do
connect
expect(connection.current_user).to eq(user)
end
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
context 'with a stale password' do
2022-08-27 11:52:29 +05:30
let(:partial_password_hash) { build(:user, password: User.random_password).authenticatable_salt }
2021-01-03 14:25:43 +05:30
let(:session_hash) { { 'warden.user.user.key' => [[user.id], partial_password_hash] } }
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
it 'sets current_user to nil' do
connect
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
expect(connection.current_user).to be_nil
end
end
2020-05-24 23:13:21 +05:30
end
2021-01-03 14:25:43 +05:30
context 'when user is not logged in' do
let(:session_hash) { {} }
2020-05-24 23:13:21 +05:30
it 'sets current_user to nil' do
connect
expect(connection.current_user).to be_nil
end
end
end
2021-01-03 14:25:43 +05:30
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-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
context 'when session cookie is an empty string' do
2020-05-24 23:13:21 +05:30
it 'sets current_user to nil' do
2021-01-03 14:25:43 +05:30
cookies[Gitlab::Application.config.session_options[:key]] = ''
2020-05-24 23:13:21 +05:30
connect
expect(connection.current_user).to be_nil
end
end
end