diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-12-07 03:05:03 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-12-07 03:05:03 +0100 |
commit | 8f1c229571b4db8dda144bf6eaa193799309e817 (patch) | |
tree | 592710207a614428d5cb809f6e13c8b546b58969 /actionpack/test/controller/session_fixation_test.rb | |
parent | 601e40e744f44fe8819be100a8c472ea161d13ab (diff) | |
parent | 9eca588bdfbb41f6b48477025d1cd8eea4a38296 (diff) | |
download | rails-8f1c229571b4db8dda144bf6eaa193799309e817.tar.gz rails-8f1c229571b4db8dda144bf6eaa193799309e817.tar.bz2 rails-8f1c229571b4db8dda144bf6eaa193799309e817.zip |
Merge commit 'mainstream/master'
Conflicts:
actionmailer/lib/action_mailer/base.rb
actionpack/lib/action_controller/base.rb
actionpack/lib/action_controller/mime_type.rb
railties/doc/guides/html/activerecord_validations_callbacks.html
railties/doc/guides/html/caching_with_rails.html
railties/doc/guides/html/command_line.html
railties/doc/guides/html/configuring.html
railties/doc/guides/html/creating_plugins.html
railties/doc/guides/html/finders.html
railties/doc/guides/html/routing_outside_in.html
railties/doc/guides/source/activerecord_validations_callbacks.txt
railties/doc/guides/source/caching_with_rails.txt
railties/doc/guides/source/command_line.txt
railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt
railties/doc/guides/source/creating_plugins/controllers.txt
railties/doc/guides/source/creating_plugins/core_ext.txt
railties/doc/guides/source/creating_plugins/helpers.txt
railties/doc/guides/source/creating_plugins/index.txt
railties/doc/guides/source/creating_plugins/migration_generator.txt
railties/doc/guides/source/creating_plugins/models.txt
railties/doc/guides/source/creating_plugins/odds_and_ends.txt
railties/doc/guides/source/creating_plugins/routes.txt
railties/doc/guides/source/finders.txt
railties/doc/guides/source/routing_outside_in.txt
railties/doc/guides/source/testing_rails_applications.txt
Diffstat (limited to 'actionpack/test/controller/session_fixation_test.rb')
-rw-r--r-- | actionpack/test/controller/session_fixation_test.rb | 93 |
1 files changed, 44 insertions, 49 deletions
diff --git a/actionpack/test/controller/session_fixation_test.rb b/actionpack/test/controller/session_fixation_test.rb index 164438c513..e8dc8bd295 100644 --- a/actionpack/test/controller/session_fixation_test.rb +++ b/actionpack/test/controller/session_fixation_test.rb @@ -1,20 +1,13 @@ require 'abstract_unit' - -class SessionFixationTest < Test::Unit::TestCase - class MockCGI < CGI #:nodoc: - attr_accessor :stdoutput, :env_table - - def initialize(env, data = '') - self.env_table = env - self.stdoutput = StringIO.new - super(nil, StringIO.new(data)) - end - end - +class SessionFixationTest < ActionController::IntegrationTest class TestController < ActionController::Base - session :session_key => '_myapp_session_id', :secret => CGI::Session.generate_unique_id, :except => :default_session_key - session :cookie_only => false, :only => :allow_session_fixation + session :session_key => '_myapp_session_id', + :secret => CGI::Session.generate_unique_id, + :except => :default_session_key + + session :cookie_only => false, + :only => :allow_session_fixation def default_session_key render :text => "default_session_key" @@ -36,54 +29,56 @@ class SessionFixationTest < Test::Unit::TestCase end def test_should_be_able_to_make_a_successful_request - cgi = mock_cgi_for_request_to(:custom_session_key, :id => 1) - - assert_nothing_raised do - @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi)) + with_test_route_set do + assert_nothing_raised do + get '/custom_session_key', :id => "1" + end + assert_equal 'custom_session_key: 1', @controller.response.body + assert_not_nil @controller.session end - assert_equal 'custom_session_key: 1', @controller.response.body - assert_not_nil @controller.session end def test_should_catch_session_fixation_attempt - cgi = mock_cgi_for_request_to(:custom_session_key, :_myapp_session_id => 42) - - assert_raises ActionController::CgiRequest::SessionFixationAttempt do - @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi)) + with_test_route_set do + assert_raises(ActionController::RackRequest::SessionFixationAttempt) do + get '/custom_session_key', :_myapp_session_id => "42" + end + assert_nil @controller.session end - assert_nil @controller.session end def test_should_not_catch_session_fixation_attempt_when_cookie_only_setting_is_disabled - cgi = mock_cgi_for_request_to(:allow_session_fixation, :_myapp_session_id => 42) - - assert_nothing_raised do - @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi)) + with_test_route_set do + assert_nothing_raised do + get '/allow_session_fixation', :_myapp_session_id => "42" + end + assert !@controller.response.body.blank? + assert_not_nil @controller.session end - assert ! @controller.response.body.blank? - assert_not_nil @controller.session end def test_should_catch_session_fixation_attempt_with_default_session_key - ActionController::Base.session_store = :p_store # using the default session_key is not possible with cookie store - cgi = mock_cgi_for_request_to(:default_session_key, :_session_id => 42) - - assert_raises ActionController::CgiRequest::SessionFixationAttempt do - @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi)) + # using the default session_key is not possible with cookie store + ActionController::Base.session_store = :p_store + + with_test_route_set do + assert_raises ActionController::RackRequest::SessionFixationAttempt do + get '/default_session_key', :_session_id => "42" + end + assert_nil @controller.response + assert_nil @controller.session end - assert @controller.response.body.blank? - assert_nil @controller.session - end - -private - - def mock_cgi_for_request_to(action, params = {}) - MockCGI.new({ - "REQUEST_METHOD" => "GET", - "QUERY_STRING" => "action=#{action}&#{params.to_query}", - "REQUEST_URI" => "/", - "SERVER_PORT" => "80", - "HTTP_HOST" => "testdomain.com" }, '') end + private + def with_test_route_set + with_routing do |set| + set.draw do |map| + map.with_options :controller => "session_fixation_test/test" do |c| + c.connect "/:action" + end + end + yield + end + end end |