From 1bff4940467df1b8a9aad1e825e577e7626b4ced Mon Sep 17 00:00:00 2001 From: abcang Date: Sat, 21 Dec 2019 19:00:47 +0900 Subject: [PATCH 1/3] Fix ActionController::TestSession#id to return Rack::Session::SessionId instance --- actionpack/lib/action_controller/test_case.rb | 4 ++-- actionpack/test/dispatch/session/test_session_test.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index f7eced7bba3a0..fc9808ca067ad 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -176,12 +176,12 @@ class LiveTestResponse < Live::Response # Methods #destroy and #load! are overridden to avoid calling methods on the # @store object, which does not exist for the TestSession class. - class TestSession < Rack::Session::Abstract::SessionHash #:nodoc: + class TestSession < Rack::Session::Abstract::PersistedSecure::SecureSessionHash #:nodoc: DEFAULT_OPTIONS = Rack::Session::Abstract::Persisted::DEFAULT_OPTIONS def initialize(session = {}) super(nil, nil) - @id = SecureRandom.hex(16) + @id = Rack::Session::SessionId.new(SecureRandom.hex(16)) @data = stringify_keys(session) @loaded = true end diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb index e90162a5fe38d..d513fccf38bd4 100644 --- a/actionpack/test/dispatch/session/test_session_test.rb +++ b/actionpack/test/dispatch/session/test_session_test.rb @@ -62,4 +62,9 @@ def test_fetch_returns_block_value session = ActionController::TestSession.new(one: "1") assert_equal(2, session.fetch("2") { |key| key.to_i }) end + + def test_session_id + session = ActionController::TestSession.new + assert_instance_of Rack::Session::SessionId, session.id + end end From ace8e1aef155dd831dfdaec5974dff19fe2b9660 Mon Sep 17 00:00:00 2001 From: abcang Date: Mon, 6 Jan 2020 12:15:45 +0900 Subject: [PATCH 2/3] test SessionId#public_id Co-Authored-By: Benjamin Quorning <22333+bquorning@users.noreply.github.com> --- actionpack/test/dispatch/session/test_session_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb index d513fccf38bd4..fffd612c58f6c 100644 --- a/actionpack/test/dispatch/session/test_session_test.rb +++ b/actionpack/test/dispatch/session/test_session_test.rb @@ -65,6 +65,6 @@ def test_fetch_returns_block_value def test_session_id session = ActionController::TestSession.new - assert_instance_of Rack::Session::SessionId, session.id + assert_instance_of String, session.id.public_id end end From 9d075d623d4fe369537993ee4f7cfde869443657 Mon Sep 17 00:00:00 2001 From: abcang Date: Wed, 8 Jan 2020 16:23:39 +0900 Subject: [PATCH 3/3] test session["session_id"] --- actionpack/test/dispatch/session/test_session_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb index fffd612c58f6c..adee2e9e038cb 100644 --- a/actionpack/test/dispatch/session/test_session_test.rb +++ b/actionpack/test/dispatch/session/test_session_test.rb @@ -66,5 +66,6 @@ def test_fetch_returns_block_value def test_session_id session = ActionController::TestSession.new assert_instance_of String, session.id.public_id + assert_equal(session.id.public_id, session["session_id"]) end end