Welcome to mirror list, hosted at ThFree Co, Russian Federation.

safe_session_store_patch_spec.rb « initializers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: abf86288364ab04686cb31e2b669d785bf00aa81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'safe_session_store_patch', feature_category: :shared do
  shared_examples 'safe session store' do
    it 'allows storing a String' do
      session[:good_data] = 'hello world'

      expect(session[:good_data]).to eq('hello world')
    end

    it 'raises error when session attempts to store an unsafe object' do
      expect { session[:test] = Struct.new(:test) }
        .to raise_error(/Serializing novel Ruby objects can cause uninitialized constants in mixed deployments/)
    end

    it 'allows instance double of OneLogin::RubySaml::Response' do
      response_double = instance_double(OneLogin::RubySaml::Response)

      session[:response_double] = response_double

      expect(session[:response_double]).to eq(response_double)
    end

    it 'raises an error for instance double of REXML::Document' do
      response_double = instance_double(REXML::Document)

      expect { session[:response_double] = response_double }
        .to raise_error(/Serializing novel Ruby objects can cause uninitialized constants in mixed deployments/)
    end
  end

  context 'with ActionController::TestSession' do
    let(:session) { ActionController::TestSession.new }

    it_behaves_like 'safe session store'
  end

  context 'with ActionDispatch::Request::Session' do
    let(:dummy_store) do
      Class.new do
        def load_session(_env)
          [1, {}]
        end

        def session_exists?(_env)
          true
        end

        def delete_session(_env, _id, _options)
          123
        end
      end.new
    end

    let(:request) { ActionDispatch::Request.new({}) }
    let(:session) { ActionDispatch::Request::Session.create(dummy_store, request, {}) }

    it_behaves_like 'safe session store'
  end
end