aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2011-04-06 12:05:58 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2011-04-06 15:47:58 -0300
commit0c5aded0922f80bd1a31c7d2a3974469a18160a8 (patch)
tree0cca53fa9dbddb4d63b31090b9c1d44d4f148a0e /actionpack/test/dispatch
parent90ecad0bc944fc3adb847c0c754d8f0dc2bed4b5 (diff)
downloadrails-0c5aded0922f80bd1a31c7d2a3974469a18160a8.tar.gz
rails-0c5aded0922f80bd1a31c7d2a3974469a18160a8.tar.bz2
rails-0c5aded0922f80bd1a31c7d2a3974469a18160a8.zip
raise if someone tries to modify the cookies when it was already streamed back to the client or converted to HTTP headers
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/cookies_test.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb
index 39159fd629..0d374e1d8b 100644
--- a/actionpack/test/dispatch/cookies_test.rb
+++ b/actionpack/test/dispatch/cookies_test.rb
@@ -495,3 +495,54 @@ class CookiesTest < ActionController::TestCase
end
end
end
+
+class CookiesIntegrationTest < ActionDispatch::IntegrationTest
+ class TestController < ActionController::Base
+ def dont_set_cookies
+ head :ok
+ end
+
+ def set_cookies
+ cookies["that"] = "hello"
+ head :ok
+ end
+ end
+
+ def test_setting_cookies_raises_after_stream_back_to_client
+ with_test_route_set do
+ env = {}
+ get '/set_cookies', nil, env
+ assert_raise(ActionDispatch::ClosedError) {
+ request.cookie_jar['alert'] = 'alert'
+ cookies['alert'] = 'alert'
+ }
+ end
+ end
+
+ def test_setting_cookies_raises_after_stream_back_to_client_even_with_an_empty_flash
+ with_test_route_set do
+ env = {}
+ get '/dont_set_cookies', nil, {}
+ assert_raise(ActionDispatch::ClosedError) {
+ request.cookie_jar['alert'] = 'alert'
+ }
+ end
+ end
+
+ private
+
+ def with_test_route_set
+ with_routing do |set|
+ set.draw do
+ match ':action', :to => CookiesIntegrationTest::TestController
+ end
+
+ @app = self.class.build_app(set) do |middleware|
+ middleware.use ActionDispatch::Cookies
+ middleware.delete "ActionDispatch::ShowExceptions"
+ end
+
+ yield
+ end
+ end
+end