2009-05-03 00:02:22 -04:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
2010-09-24 20:15:52 -04:00
|
|
|
class ShowExceptionsTest < ActionDispatch::IntegrationTest
|
2010-10-11 10:55:07 -04:00
|
|
|
|
2009-05-03 00:02:22 -04:00
|
|
|
Boomer = lambda do |env|
|
|
|
|
req = ActionDispatch::Request.new(env)
|
|
|
|
case req.path
|
|
|
|
when "/not_found"
|
|
|
|
raise ActionController::UnknownAction
|
|
|
|
when "/method_not_allowed"
|
|
|
|
raise ActionController::MethodNotAllowed
|
|
|
|
when "/not_implemented"
|
|
|
|
raise ActionController::NotImplemented
|
|
|
|
when "/unprocessable_entity"
|
|
|
|
raise ActionController::InvalidAuthenticityToken
|
2010-10-11 10:55:07 -04:00
|
|
|
when "/not_found_original_exception"
|
|
|
|
raise ActionView::Template::Error.new('template', {}, AbstractController::ActionNotFound.new)
|
2009-05-03 00:02:22 -04:00
|
|
|
else
|
|
|
|
raise "puke!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ProductionApp = ActionDispatch::ShowExceptions.new(Boomer, false)
|
|
|
|
DevelopmentApp = ActionDispatch::ShowExceptions.new(Boomer, true)
|
|
|
|
|
|
|
|
test "rescue in public from a remote ip" do
|
2009-09-26 21:51:05 -04:00
|
|
|
@app = ProductionApp
|
2009-05-03 00:02:22 -04:00
|
|
|
self.remote_addr = '208.77.188.166'
|
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/", {}, {'action_dispatch.show_exceptions' => true}
|
2009-05-03 00:02:22 -04:00
|
|
|
assert_response 500
|
|
|
|
assert_equal "500 error fixture\n", body
|
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
|
2009-05-03 00:02:22 -04:00
|
|
|
assert_response 404
|
|
|
|
assert_equal "404 error fixture\n", body
|
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
|
2009-05-03 00:02:22 -04:00
|
|
|
assert_response 405
|
|
|
|
assert_equal "", body
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rescue locally from a local request" do
|
2009-09-26 21:51:05 -04:00
|
|
|
@app = ProductionApp
|
2010-06-06 16:56:48 -04:00
|
|
|
['127.0.0.1', '127.0.0.127', '::1', '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1%0'].each do |ip_address|
|
2010-01-16 08:51:42 -05:00
|
|
|
self.remote_addr = ip_address
|
2009-05-03 00:02:22 -04:00
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/", {}, {'action_dispatch.show_exceptions' => true}
|
2010-01-16 08:51:42 -05:00
|
|
|
assert_response 500
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/puke/, body)
|
2009-05-03 00:02:22 -04:00
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
|
2010-01-16 08:51:42 -05:00
|
|
|
assert_response 404
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/#{ActionController::UnknownAction.name}/, body)
|
2009-05-03 00:02:22 -04:00
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
|
2010-01-16 08:51:42 -05:00
|
|
|
assert_response 405
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/ActionController::MethodNotAllowed/, body)
|
2010-01-16 08:51:42 -05:00
|
|
|
end
|
2009-05-03 00:02:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "localize public rescue message" do
|
|
|
|
# Change locale
|
2009-09-19 14:22:09 -04:00
|
|
|
old_locale, I18n.locale = I18n.locale, :da
|
2009-05-03 00:02:22 -04:00
|
|
|
|
|
|
|
begin
|
2009-09-26 21:51:05 -04:00
|
|
|
@app = ProductionApp
|
2009-05-03 00:02:22 -04:00
|
|
|
self.remote_addr = '208.77.188.166'
|
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/", {}, {'action_dispatch.show_exceptions' => true}
|
2009-05-03 00:02:22 -04:00
|
|
|
assert_response 500
|
|
|
|
assert_equal "500 localized error fixture\n", body
|
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
|
2009-05-03 00:02:22 -04:00
|
|
|
assert_response 404
|
|
|
|
assert_equal "404 error fixture\n", body
|
|
|
|
ensure
|
|
|
|
I18n.locale = old_locale
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "always rescue locally in development mode" do
|
2009-09-26 21:51:05 -04:00
|
|
|
@app = DevelopmentApp
|
2009-05-03 00:02:22 -04:00
|
|
|
self.remote_addr = '208.77.188.166'
|
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/", {}, {'action_dispatch.show_exceptions' => true}
|
2009-05-03 00:02:22 -04:00
|
|
|
assert_response 500
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/puke/, body)
|
2009-05-03 00:02:22 -04:00
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
|
2009-05-03 00:02:22 -04:00
|
|
|
assert_response 404
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/#{ActionController::UnknownAction.name}/, body)
|
2009-05-03 00:02:22 -04:00
|
|
|
|
2010-01-19 10:05:34 -05:00
|
|
|
get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
|
2009-05-03 00:02:22 -04:00
|
|
|
assert_response 405
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/ActionController::MethodNotAllowed/, body)
|
2009-05-03 00:02:22 -04:00
|
|
|
end
|
2010-04-06 18:45:56 -04:00
|
|
|
|
|
|
|
test "does not show filtered parameters" do
|
|
|
|
@app = DevelopmentApp
|
|
|
|
|
|
|
|
get "/", {"foo"=>"bar"}, {'action_dispatch.show_exceptions' => true,
|
|
|
|
'action_dispatch.parameter_filter' => [:foo]}
|
|
|
|
assert_response 500
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(""foo"=>"[FILTERED]"", body)
|
2010-04-06 18:45:56 -04:00
|
|
|
end
|
2010-10-11 10:55:07 -04:00
|
|
|
|
|
|
|
test "show registered original exception for wrapped exceptions when consider_all_requests_local is false" do
|
|
|
|
@app = ProductionApp
|
|
|
|
self.remote_addr = '208.77.188.166'
|
|
|
|
|
|
|
|
get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true}
|
|
|
|
assert_response 404
|
|
|
|
assert_match(/404 error/, body)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "show registered original exception for wrapped exceptions when consider_all_requests_local is true" do
|
|
|
|
@app = DevelopmentApp
|
|
|
|
|
|
|
|
get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true}
|
|
|
|
assert_response 404
|
|
|
|
assert_match(/AbstractController::ActionNotFound/, body)
|
|
|
|
end
|
2009-05-03 00:02:22 -04:00
|
|
|
end
|