Ticket #8649: flash_preservation.diff
| File flash_preservation.diff, 2.4 kB (added by fogle, 1 year ago) |
|---|
-
test/ssl_requirement_test.rb
old new 44 44 def d 45 45 render :nothing => true 46 46 end 47 48 def set_flash 49 flash[:foo] = "bar" 50 end 47 51 end 48 52 49 53 class SslRequirementTest < Test::Unit::TestCase … … 53 57 @response = ActionController::TestResponse.new 54 58 end 55 59 60 def test_redirect_to_https_preserves_flash 61 get :set_flash 62 get :b 63 assert_response :redirect 64 assert_equal "bar", flash[:foo] 65 end 66 67 def test_not_redirecting_to_https_does_not_preserve_the_flash 68 get :set_flash 69 get :d 70 assert_response :success 71 assert_nil flash[:foo] 72 end 73 74 def test_redirect_to_http_preserves_flash 75 get :set_flash 76 @request.env['HTTPS'] = "on" 77 get :d 78 assert_response :redirect 79 assert_equal "bar", flash[:foo] 80 end 81 82 def test_not_redirecting_to_http_does_not_preserve_the_flash 83 get :set_flash 84 @request.env['HTTPS'] = "on" 85 get :a 86 assert_response :success 87 assert_nil flash[:foo] 88 end 89 56 90 def test_required_without_ssl 57 91 assert_not_equal "on", @request.env["HTTPS"] 58 92 get :a 59 93 assert_response :redirect 60 assert_match %r{^https://}, @response.headers[' location']94 assert_match %r{^https://}, @response.headers['Location'] 61 95 get :b 62 96 assert_response :redirect 63 assert_match %r{^https://}, @response.headers[' location']97 assert_match %r{^https://}, @response.headers['Location'] 64 98 end 65 99 66 100 def test_required_with_ssl … … 81 115 @request.env['HTTPS'] = "on" 82 116 get :d 83 117 assert_response :redirect 84 assert_match %r{^http://}, @response.headers[' location']118 assert_match %r{^http://}, @response.headers['Location'] 85 119 end 86 120 87 121 def test_allowed_without_ssl -
lib/ssl_requirement.rb
old new 51 51 52 52 if ssl_required? && !request.ssl? 53 53 redirect_to "https://" + request.host + request.request_uri 54 flash.keep 54 55 return false 55 56 elsif request.ssl? && !ssl_required? 56 57 redirect_to "http://" + request.host + request.request_uri 58 flash.keep 57 59 return false 58 60 end 59 61 end