diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/dispatcher_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 31 | ||||
-rw-r--r-- | actionpack/test/controller/rack_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/session/cookie_store_test.rb | 26 | ||||
-rw-r--r-- | actionpack/test/controller/session_fixation_test.rb | 84 |
5 files changed, 62 insertions, 91 deletions
diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 30dda87bb4..fd06b4ea99 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -50,7 +50,7 @@ class DispatcherTest < Test::Unit::TestCase end def test_failsafe_response - Dispatcher.any_instance.expects(:dispatch_unlocked).raises('b00m') + Dispatcher.any_instance.expects(:dispatch).raises('b00m') ActionController::Failsafe.any_instance.expects(:log_failsafe_exception) assert_nothing_raised do @@ -96,7 +96,9 @@ class DispatcherTest < Test::Unit::TestCase private def dispatch(cache_classes = true) - Dispatcher.any_instance.stubs(:handle_request).returns([200, {}, 'response']) + controller = mock() + controller.stubs(:process).returns([200, {}, 'response']) + ActionController::Routing::Routes.stubs(:recognize).returns(controller) Dispatcher.define_dispatcher_callbacks(cache_classes) @dispatcher.call({}) end diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index fd985a9a46..c28050fe0d 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -373,4 +373,35 @@ class IntegrationProcessTest < ActionController::IntegrationTest end end +class MetalTest < ActionController::IntegrationTest + class Poller + def self.call(env) + if env["PATH_INFO"] =~ /^\/success/ + [200, {"Content-Type" => "text/plain"}, "Hello World!"] + else + [404, {"Content-Type" => "text/plain"}, ''] + end + end + end + + def setup + @integration_session = ActionController::Integration::Session.new(Poller) + end + + def test_successful_get + get "/success" + assert_response 200 + assert_response :success + assert_response :ok + assert_equal "Hello World!", response.body + end + + def test_failed_get + get "/failure" + assert_response 404 + assert_response :not_found + assert_equal '', response.body + end +end + end diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index e2ec686c41..3a8a00b7d7 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -236,7 +236,7 @@ class RackResponseTest < BaseRackTest @response.body = "Hello, World!" @response.prepare! - status, headers, body = @response.out + status, headers, body = @response.to_a assert_equal "200 OK", status assert_equal({ "Content-Type" => "text/html; charset=utf-8", @@ -257,7 +257,7 @@ class RackResponseTest < BaseRackTest end @response.prepare! - status, headers, body = @response.out + status, headers, body = @response.to_a assert_equal "200 OK", status assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers) @@ -293,6 +293,6 @@ class RackResponseHeadersTest < BaseRackTest private def response_headers @response.prepare! - @response.out[1] + @response.to_a[1] end end diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb index 8098059d46..ad8ff09884 100644 --- a/actionpack/test/controller/session/cookie_store_test.rb +++ b/actionpack/test/controller/session/cookie_store_test.rb @@ -9,6 +9,8 @@ class CookieStoreTest < ActionController::IntegrationTest CookieStoreApp = ActionController::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret) + Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1') + SignedBar = "BAh7BjoIZm9vIghiYXI%3D--" + "fef868465920f415f2c0652d6910d3af288a0367" @@ -17,9 +19,13 @@ class CookieStoreTest < ActionController::IntegrationTest head :ok end + def persistent_session_id + render :text => session[:session_id] + end + def set_session_value session[:foo] = "bar" - head :ok + render :text => Marshal.dump(session.to_hash) end def get_session_value @@ -83,7 +89,8 @@ class CookieStoreTest < ActionController::IntegrationTest with_test_route_set do get '/set_session_value' assert_response :success - assert_equal ["_myapp_session=#{SignedBar}; path=/"], + session_payload = Verifier.generate( Marshal.load(response.body) ) + assert_equal ["_myapp_session=#{session_payload}; path=/"], headers['Set-Cookie'] end end @@ -132,6 +139,21 @@ class CookieStoreTest < ActionController::IntegrationTest end end + def test_persistent_session_id + with_test_route_set do + cookies[SessionKey] = SignedBar + get '/persistent_session_id' + assert_response :success + assert_equal response.body.size, 32 + session_id = response.body + get '/persistent_session_id' + assert_equal session_id, response.body + reset! + get '/persistent_session_id' + assert_not_equal session_id, response.body + end + end + private def with_test_route_set with_routing do |set| diff --git a/actionpack/test/controller/session_fixation_test.rb b/actionpack/test/controller/session_fixation_test.rb deleted file mode 100644 index 9e5b45dc3d..0000000000 --- a/actionpack/test/controller/session_fixation_test.rb +++ /dev/null @@ -1,84 +0,0 @@ -# require 'abstract_unit' -# -# 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 -# -# def default_session_key -# render :text => "default_session_key" -# end -# -# def custom_session_key -# render :text => "custom_session_key: #{params[:id]}" -# end -# -# def allow_session_fixation -# render :text => "allow_session_fixation" -# end -# -# def rescue_action(e) raise end -# end -# -# def setup -# @controller = TestController.new -# end -# -# def test_should_be_able_to_make_a_successful_request -# 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 -# end -# -# def test_should_catch_session_fixation_attempt -# 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 -# end -# -# def test_should_not_catch_session_fixation_attempt_when_cookie_only_setting_is_disabled -# 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 -# end -# -# def test_should_catch_session_fixation_attempt_with_default_session_key -# # 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 -# 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 |