Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

SSL requirement plugin keeps flash when it redirects. Closes #8649 [r…

…undeks, fogle]
  • Loading branch information...
commit 34a9a138c4093bd7d5678822f8f1e62c31d47299 1 parent aa2dded
Jeremy Kemper authored February 02, 2008
2  lib/ssl_requirement.rb
@@ -51,9 +51,11 @@ def ensure_proper_protocol
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
40  test/ssl_requirement_test.rb
@@ -44,6 +44,10 @@ def c
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,14 +57,44 @@ def setup
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,7 +115,7 @@ def test_disallowed_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

0 notes on commit 34a9a13

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