aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorLukasz Sarnacki <lukesarnacki@gmail.com>2014-01-10 12:57:50 +0100
committerLukasz Sarnacki <lukesarnacki@gmail.com>2014-01-29 17:05:00 +0100
commitb23ffd0dac895aa3fd3afd8d9be36794941731b2 (patch)
treea287df4bfcaff9c0838d3f4062a02fd1e5134b9f /actionpack/test
parentf142527eb30626904cb1e655a1a28801f08b8acf (diff)
downloadrails-b23ffd0dac895aa3fd3afd8d9be36794941731b2.tar.gz
rails-b23ffd0dac895aa3fd3afd8d9be36794941731b2.tar.bz2
rails-b23ffd0dac895aa3fd3afd8d9be36794941731b2.zip
Allow session serializer key in config.session_store
MessageEncryptor has :serializer option, where any serializer object can be passed. This commit make it possible to set this serializer from configuration level. There are predefined serializers (:marshal_serializer, :json_serialzier) and custom serializer can be passed as String, Symbol (camelized and constantized in ActionDispatch::Session namepspace) or serializer object. Default :json_serializer was also added to generators to provide secure defalt.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/dispatch/cookies_test.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb
index 91ac13e7c6..b19ce905f5 100644
--- a/actionpack/test/dispatch/cookies_test.rb
+++ b/actionpack/test/dispatch/cookies_test.rb
@@ -379,6 +379,39 @@ class CookiesTest < ActionController::TestCase
assert_equal 'bar', cookies.encrypted[:foo]
end
+ class ActionDispatch::Session::CustomJsonSerializer
+ def self.load(value)
+ JSON.load(value) + " and loaded"
+ end
+
+ def self.dump(value)
+ JSON.dump(value + " was dumped")
+ end
+ end
+
+ def test_encrypted_cookie_using_custom_json_serializer
+ @request.env["action_dispatch.session_serializer"] = :custom_json_serializer
+ get :set_encrypted_cookie
+ assert_equal 'bar was dumped and loaded', cookies.encrypted[:foo]
+ end
+
+ def test_encrypted_cookie_using_serializer_object
+ @request.env["action_dispatch.session_serializer"] = ActionDispatch::Session::CustomJsonSerializer
+ get :set_encrypted_cookie
+ assert_equal 'bar was dumped and loaded', cookies.encrypted[:foo]
+ end
+
+ def test_encrypted_cookie_using_json_serializer
+ @request.env["action_dispatch.session_serializer"] = :json_serializer
+ get :set_encrypted_cookie
+ cookies = @controller.send :cookies
+ assert_not_equal 'bar', cookies[:foo]
+ assert_raises TypeError do
+ cookies.signed[:foo]
+ end
+ assert_equal 'bar', cookies.encrypted[:foo]
+ end
+
def test_accessing_nonexistant_encrypted_cookie_should_not_raise_invalid_message
get :set_encrypted_cookie
assert_nil @controller.send(:cookies).encrypted[:non_existant_attribute]