Permalink
Browse files

Changed the tests to ensure HybridSerializer actually migrates the co…

…okies (currently failing)
  • Loading branch information...
1 parent 6de4888 commit ba6861d032013416034cdb20012962b97460795f @chancancode chancancode committed Feb 8, 2014
Showing with 18 additions and 10 deletions.
  1. +18 −10 actionpack/test/dispatch/cookies_test.rb
@@ -399,20 +399,24 @@ def test_signed_cookie_using_custom_serializer
assert_equal '45 was dumped and loaded', cookies.signed[:user_id]
end
- def test_signed_cookie_using_hybrid_serializer_can_read_from_marshal_dumped_value
+ def test_signed_cookie_using_hybrid_serializer_can_migrate_marshal_dumped_value_to_json
@request.env["action_dispatch.cookies_serializer"] = :hybrid
key_generator = @request.env["action_dispatch.key_generator"]
signed_cookie_salt = @request.env["action_dispatch.signed_cookie_salt"]
secret = key_generator.generate_key(signed_cookie_salt)
- legacy_value = ActiveSupport::MessageVerifier.new(secret, serializer: Marshal).generate(45)
- @request.headers["Cookie"] = "user_id=#{legacy_value}"
+
+ marshal_value = ActiveSupport::MessageVerifier.new(secret, serializer: Marshal).generate(45)
+ @request.headers["Cookie"] = "user_id=#{marshal_value}"
get :get_signed_cookie
cookies = @controller.send :cookies
assert_not_equal 45, cookies[:user_id]
assert_equal 45, cookies.signed[:user_id]
+
+ json_value = ActiveSupport::MessageVerifier.new(secret, serializer: JSON).generate(45)
+ assert_equal @response.cookies['user_id'], json_value
end
def test_signed_cookie_using_hybrid_serializer_can_read_from_json_dumped_value
@@ -421,8 +425,8 @@ def test_signed_cookie_using_hybrid_serializer_can_read_from_json_dumped_value
key_generator = @request.env["action_dispatch.key_generator"]
signed_cookie_salt = @request.env["action_dispatch.signed_cookie_salt"]
secret = key_generator.generate_key(signed_cookie_salt)
- legacy_value = ActiveSupport::MessageVerifier.new(secret, serializer: JSON).generate(45)
- @request.headers["Cookie"] = "user_id=#{legacy_value}"
+ json_value = ActiveSupport::MessageVerifier.new(secret, serializer: JSON).generate(45)
+ @request.headers["Cookie"] = "user_id=#{json_value}"
get :get_signed_cookie
@@ -475,22 +479,26 @@ def test_encrypted_cookie_using_custom_serializer
assert_equal 'bar was dumped and loaded', cookies.encrypted[:foo]
end
- def test_encrypted_cookie_using_hybrid_serializer_can_read_from_marshal_dumped_value
+ def test_encrypted_cookie_using_hybrid_serializer_can_migrate_marshal_dumped_value_to_json
@request.env["action_dispatch.cookies_serializer"] = :hybrid
key_generator = @request.env["action_dispatch.key_generator"]
encrypted_cookie_salt = @request.env["action_dispatch.encrypted_cookie_salt"]
encrypted_signed_cookie_salt = @request.env["action_dispatch.encrypted_signed_cookie_salt"]
secret = key_generator.generate_key(encrypted_cookie_salt)
sign_secret = key_generator.generate_key(encrypted_signed_cookie_salt)
- legacy_value = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: Marshal).encrypt_and_sign(45)
- @request.headers["Cookie"] = "user_id=#{legacy_value}"
+
+ marshal_value = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: Marshal).encrypt_and_sign(45)
+ @request.headers["Cookie"] = "user_id=#{marshal_value}"
get :get_encrypted_cookie
cookies = @controller.send :cookies
assert_not_equal 45, cookies[:user_id]
assert_equal 45, cookies.encrypted[:user_id]
+
+ json_value = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: JSON).encrypt_and_sign(45)
+ assert_equal @response.cookies["user_id"], json_value
end
def test_encrypted_cookie_using_hybrid_serializer_can_read_from_json_dumped_value
@@ -501,8 +509,8 @@ def test_encrypted_cookie_using_hybrid_serializer_can_read_from_json_dumped_valu
encrypted_signed_cookie_salt = @request.env["action_dispatch.encrypted_signed_cookie_salt"]
secret = key_generator.generate_key(encrypted_cookie_salt)
sign_secret = key_generator.generate_key(encrypted_signed_cookie_salt)
- legacy_value = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: JSON).encrypt_and_sign(45)
- @request.headers["Cookie"] = "user_id=#{legacy_value}"
+ json_value = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: JSON).encrypt_and_sign(45)
+ @request.headers["Cookie"] = "user_id=#{json_value}"
get :get_encrypted_cookie

0 comments on commit ba6861d

Please sign in to comment.