Skip to content
This repository
Browse code

Merge pull request #4429 from marcinbunsch/1923-force-ssl-redirect-ke…

…ep-flash

When force redirecting to SSL, make sure that the session is kept
  • Loading branch information...
commit ef1dfb62d7becb14c3905f1b86f811f2fd8721d6 2 parents 488c9ef + 321dae5
José Valim josevalim authored
1  actionpack/lib/action_controller/metal/force_ssl.rb
@@ -29,6 +29,7 @@ def force_ssl(options = {})
29 29 if !request.ssl? && !Rails.env.development?
30 30 redirect_options = {:protocol => 'https://', :status => :moved_permanently}
31 31 redirect_options.merge!(:host => host) if host
  32 + flash.keep
32 33 redirect_to redirect_options
33 34 end
34 35 end
38 actionpack/test/controller/force_ssl_test.rb
@@ -26,6 +26,23 @@ class ForceSSLExceptAction < ForceSSLController
26 26 force_ssl :except => :banana
27 27 end
28 28
  29 +class ForceSSLFlash < ForceSSLController
  30 + force_ssl :except => [:banana, :set_flash, :use_flash]
  31 +
  32 + def set_flash
  33 + flash["that"] = "hello"
  34 + redirect_to '/force_ssl_flash/cheeseburger'
  35 + end
  36 +
  37 + def use_flash
  38 + @flash_copy = {}.update flash
  39 + @flashy = flash["that"]
  40 + render :inline => "hello"
  41 + end
  42 +
  43 +end
  44 +
  45 +
29 46 class ForceSSLControllerLevelTest < ActionController::TestCase
30 47 tests ForceSSLControllerLevel
31 48
@@ -50,7 +67,7 @@ def test_banana_redirects_to_https_with_custom_host
50 67 assert_response 301
51 68 assert_equal "https://secure.test.host/force_ssl_custom_domain/banana", redirect_to_url
52 69 end
53   -
  70 +
54 71 def test_cheeseburger_redirects_to_https_with_custom_host
55 72 get :cheeseburger
56 73 assert_response 301
@@ -101,3 +118,22 @@ def test_development_environment_not_redirects_to_https
101 118 assert_response 200
102 119 end
103 120 end
  121 +
  122 +class ForceSSLFlashTest < ActionController::TestCase
  123 + tests ForceSSLFlash
  124 +
  125 + def test_cheeseburger_redirects_to_https
  126 + get :set_flash
  127 + assert_response 302
  128 + assert_equal "http://test.host/force_ssl_flash/cheeseburger", redirect_to_url
  129 +
  130 + get :cheeseburger
  131 + assert_response 301
  132 + assert_equal "https://test.host/force_ssl_flash/cheeseburger", redirect_to_url
  133 +
  134 + get :use_flash
  135 + assert_equal "hello", assigns["flash_copy"]["that"]
  136 + assert_equal "hello", assigns["flashy"]
  137 + end
  138 +
  139 +end

0 comments on commit ef1dfb6

Please sign in to comment.
Something went wrong with that request. Please try again.