2017-07-01 16:09:13 -04:00
|
|
|
# frozen_string_literal: true
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2011-12-01 15:15:42 -05:00
|
|
|
|
|
|
|
class DebugExceptionsTest < ActionDispatch::IntegrationTest
|
|
|
|
class Boomer
|
2011-12-14 11:03:35 -05:00
|
|
|
attr_accessor :closed
|
|
|
|
|
2011-12-01 15:15:42 -05:00
|
|
|
def initialize(detailed = false)
|
|
|
|
@detailed = detailed
|
2011-12-14 11:03:35 -05:00
|
|
|
@closed = false
|
|
|
|
end
|
|
|
|
|
2014-07-28 11:22:11 -04:00
|
|
|
# We're obliged to implement this (even though it doesn't actually
|
|
|
|
# get called here) to properly comply with the Rack SPEC
|
2011-12-14 11:03:35 -05:00
|
|
|
def each
|
|
|
|
end
|
|
|
|
|
|
|
|
def close
|
|
|
|
@closed = true
|
2011-12-01 15:15:42 -05:00
|
|
|
end
|
|
|
|
|
2014-10-23 12:53:43 -04:00
|
|
|
def method_that_raises
|
2016-08-06 12:54:50 -04:00
|
|
|
raise StandardError.new "error in framework"
|
2014-10-23 12:53:43 -04:00
|
|
|
end
|
|
|
|
|
2011-12-01 15:15:42 -05:00
|
|
|
def call(env)
|
2016-08-06 12:54:50 -04:00
|
|
|
env["action_dispatch.show_detailed_exceptions"] = @detailed
|
2011-12-01 15:15:42 -05:00
|
|
|
req = ActionDispatch::Request.new(env)
|
|
|
|
case req.path
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/pass}
|
2011-12-14 11:03:35 -05:00
|
|
|
[404, { "X-Cascade" => "pass" }, self]
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/not_found}
|
2012-01-14 15:25:11 -05:00
|
|
|
raise AbstractController::ActionNotFound
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/runtime_error}
|
2011-12-01 15:15:42 -05:00
|
|
|
raise RuntimeError
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/method_not_allowed}
|
2011-12-01 15:15:42 -05:00
|
|
|
raise ActionController::MethodNotAllowed
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/unknown_http_method}
|
2013-04-22 09:09:41 -04:00
|
|
|
raise ActionController::UnknownHttpMethod
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/not_implemented}
|
2011-12-01 15:15:42 -05:00
|
|
|
raise ActionController::NotImplemented
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/unprocessable_entity}
|
2011-12-01 15:15:42 -05:00
|
|
|
raise ActionController::InvalidAuthenticityToken
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/not_found_original_exception}
|
2015-11-03 09:54:34 -05:00
|
|
|
begin
|
|
|
|
raise AbstractController::ActionNotFound.new
|
|
|
|
rescue
|
2016-08-06 12:54:50 -04:00
|
|
|
raise ActionView::Template::Error.new("template")
|
2015-11-03 09:54:34 -05:00
|
|
|
end
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/missing_template}
|
2016-08-06 12:54:50 -04:00
|
|
|
raise ActionView::MissingTemplate.new(%w(foo), "foo/index", %w(foo), false, "mailer")
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/bad_request}
|
2012-05-20 05:04:12 -04:00
|
|
|
raise ActionController::BadRequest
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/missing_keys}
|
2012-08-01 16:33:15 -04:00
|
|
|
raise ActionController::UrlGenerationError, "No route matches"
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/parameter_missing}
|
2013-01-15 19:07:13 -05:00
|
|
|
raise ActionController::ParameterMissing, :missing_param_key
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/original_syntax_error}
|
2016-08-06 12:54:50 -04:00
|
|
|
eval "broke_syntax =" # `eval` need for raise native SyntaxError at runtime
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/syntax_error_into_view}
|
2014-01-30 09:33:49 -05:00
|
|
|
begin
|
2016-08-06 12:54:50 -04:00
|
|
|
eval "broke_syntax ="
|
2015-11-03 09:54:34 -05:00
|
|
|
rescue Exception
|
2014-01-30 09:33:49 -05:00
|
|
|
template = ActionView::Template.new(File.read(__FILE__),
|
|
|
|
__FILE__,
|
|
|
|
ActionView::Template::Handlers::Raw.new,
|
|
|
|
{})
|
2015-11-03 09:54:34 -05:00
|
|
|
raise ActionView::Template::Error.new(template)
|
2014-01-30 09:33:49 -05:00
|
|
|
end
|
2016-05-07 21:44:38 -04:00
|
|
|
when %r{/framework_raises}
|
2014-10-23 12:53:43 -04:00
|
|
|
method_that_raises
|
2011-12-01 15:15:42 -05:00
|
|
|
else
|
|
|
|
raise "puke!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-05 07:59:00 -05:00
|
|
|
RoutesApp = Struct.new(:routes).new(SharedTestRoutes)
|
|
|
|
ProductionApp = ActionDispatch::DebugExceptions.new(Boomer.new(false), RoutesApp)
|
|
|
|
DevelopmentApp = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp)
|
2011-12-01 15:15:42 -05:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "skip diagnosis if not showing detailed exceptions" do
|
2011-12-01 15:15:42 -05:00
|
|
|
@app = ProductionApp
|
|
|
|
assert_raise RuntimeError do
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/", headers: { "action_dispatch.show_exceptions" => true }
|
2011-12-01 15:15:42 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "skip diagnosis if not showing exceptions" do
|
2011-12-01 15:15:42 -05:00
|
|
|
@app = DevelopmentApp
|
|
|
|
assert_raise RuntimeError do
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/", headers: { "action_dispatch.show_exceptions" => false }
|
2011-12-01 15:15:42 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "raise an exception on cascade pass" do
|
2011-12-03 05:38:25 -05:00
|
|
|
@app = ProductionApp
|
|
|
|
assert_raise ActionController::RoutingError do
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/pass", headers: { "action_dispatch.show_exceptions" => true }
|
2011-12-03 05:38:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "closes the response body on cascade pass" do
|
2011-12-14 11:03:35 -05:00
|
|
|
boomer = Boomer.new(false)
|
|
|
|
@app = ActionDispatch::DebugExceptions.new(boomer)
|
|
|
|
assert_raise ActionController::RoutingError do
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/pass", headers: { "action_dispatch.show_exceptions" => true }
|
2011-12-14 11:03:35 -05:00
|
|
|
end
|
|
|
|
assert boomer.closed, "Expected to close the response body"
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "displays routes in a table when a RoutingError occurs" do
|
2013-01-05 07:59:00 -05:00
|
|
|
@app = DevelopmentApp
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/pass", headers: { "action_dispatch.show_exceptions" => true }
|
2013-01-05 07:59:00 -05:00
|
|
|
routing_table = body[/route_table.*<.table>/m]
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_match "/:controller(/:action)(.:format)", routing_table
|
|
|
|
assert_match ":controller#:action", routing_table
|
|
|
|
assert_no_match "<|>", routing_table, "there should not be escaped html in the output"
|
2013-01-05 07:59:00 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "displays request and response info when a RoutingError occurs" do
|
2014-11-24 11:54:03 -05:00
|
|
|
@app = DevelopmentApp
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/pass", headers: { "action_dispatch.show_exceptions" => true }
|
2014-11-24 11:54:03 -05:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_select "h2", /Request/
|
|
|
|
assert_select "h2", /Response/
|
2014-11-24 11:54:03 -05:00
|
|
|
end
|
|
|
|
|
2011-12-01 15:15:42 -05:00
|
|
|
test "rescue with diagnostics message" do
|
|
|
|
@app = DevelopmentApp
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/", headers: { "action_dispatch.show_exceptions" => true }
|
2011-12-01 15:15:42 -05:00
|
|
|
assert_response 500
|
|
|
|
assert_match(/puke/, body)
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/not_found", headers: { "action_dispatch.show_exceptions" => true }
|
2011-12-01 15:15:42 -05:00
|
|
|
assert_response 404
|
2012-01-14 15:25:11 -05:00
|
|
|
assert_match(/#{AbstractController::ActionNotFound.name}/, body)
|
2011-12-01 15:15:42 -05:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/method_not_allowed", headers: { "action_dispatch.show_exceptions" => true }
|
2011-12-01 15:15:42 -05:00
|
|
|
assert_response 405
|
|
|
|
assert_match(/ActionController::MethodNotAllowed/, body)
|
2012-05-20 05:04:12 -04:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/unknown_http_method", headers: { "action_dispatch.show_exceptions" => true }
|
2013-04-22 09:09:41 -04:00
|
|
|
assert_response 405
|
|
|
|
assert_match(/ActionController::UnknownHttpMethod/, body)
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/bad_request", headers: { "action_dispatch.show_exceptions" => true }
|
2012-05-20 05:04:12 -04:00
|
|
|
assert_response 400
|
|
|
|
assert_match(/ActionController::BadRequest/, body)
|
2013-01-15 19:07:13 -05:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/parameter_missing", headers: { "action_dispatch.show_exceptions" => true }
|
2013-01-15 19:07:13 -05:00
|
|
|
assert_response 400
|
|
|
|
assert_match(/ActionController::ParameterMissing/, body)
|
2011-12-01 15:15:42 -05:00
|
|
|
end
|
|
|
|
|
2013-08-21 08:42:04 -04:00
|
|
|
test "rescue with text error for xhr request" do
|
|
|
|
@app = DevelopmentApp
|
2016-08-16 03:30:11 -04:00
|
|
|
xhr_request_env = { "action_dispatch.show_exceptions" => true, "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" }
|
2013-08-21 08:42:04 -04:00
|
|
|
|
2015-01-04 04:35:06 -05:00
|
|
|
get "/", headers: xhr_request_env
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_response 500
|
2014-04-14 09:45:40 -04:00
|
|
|
assert_no_match(/<header>/, body)
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_no_match(/<body>/, body)
|
2014-08-18 02:29:21 -04:00
|
|
|
assert_equal "text/plain", response.content_type
|
2014-04-14 09:45:40 -04:00
|
|
|
assert_match(/RuntimeError\npuke/, body)
|
2013-08-21 08:42:04 -04:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
Rails.stub :root, Pathname.new(".") do
|
2015-11-03 16:26:59 -05:00
|
|
|
get "/", headers: xhr_request_env
|
|
|
|
|
|
|
|
assert_response 500
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_match "Extracted source (around line #", body
|
|
|
|
assert_select "pre", { count: 0 }, body
|
2015-11-03 16:26:59 -05:00
|
|
|
end
|
|
|
|
|
2015-01-04 04:35:06 -05:00
|
|
|
get "/not_found", headers: xhr_request_env
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_response 404
|
|
|
|
assert_no_match(/<body>/, body)
|
2014-08-18 02:29:21 -04:00
|
|
|
assert_equal "text/plain", response.content_type
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_match(/#{AbstractController::ActionNotFound.name}/, body)
|
|
|
|
|
2015-01-04 04:35:06 -05:00
|
|
|
get "/method_not_allowed", headers: xhr_request_env
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_response 405
|
|
|
|
assert_no_match(/<body>/, body)
|
2014-08-18 02:29:21 -04:00
|
|
|
assert_equal "text/plain", response.content_type
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_match(/ActionController::MethodNotAllowed/, body)
|
|
|
|
|
2015-01-04 04:35:06 -05:00
|
|
|
get "/unknown_http_method", headers: xhr_request_env
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_response 405
|
|
|
|
assert_no_match(/<body>/, body)
|
2014-08-18 02:29:21 -04:00
|
|
|
assert_equal "text/plain", response.content_type
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_match(/ActionController::UnknownHttpMethod/, body)
|
|
|
|
|
2015-01-04 04:35:06 -05:00
|
|
|
get "/bad_request", headers: xhr_request_env
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_response 400
|
|
|
|
assert_no_match(/<body>/, body)
|
2014-08-18 02:29:21 -04:00
|
|
|
assert_equal "text/plain", response.content_type
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_match(/ActionController::BadRequest/, body)
|
|
|
|
|
2015-01-04 04:35:06 -05:00
|
|
|
get "/parameter_missing", headers: xhr_request_env
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_response 400
|
|
|
|
assert_no_match(/<body>/, body)
|
2014-08-18 02:29:21 -04:00
|
|
|
assert_equal "text/plain", response.content_type
|
2013-08-21 08:42:04 -04:00
|
|
|
assert_match(/ActionController::ParameterMissing/, body)
|
|
|
|
end
|
|
|
|
|
2016-05-07 21:44:38 -04:00
|
|
|
test "rescue with JSON error for JSON API request" do
|
2015-07-20 15:38:09 -04:00
|
|
|
@app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api)
|
2015-07-07 11:43:49 -04:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/", headers: { "action_dispatch.show_exceptions" => true }, as: :json
|
2015-07-07 11:43:49 -04:00
|
|
|
assert_response 500
|
|
|
|
assert_no_match(/<header>/, body)
|
|
|
|
assert_no_match(/<body>/, body)
|
|
|
|
assert_equal "application/json", response.content_type
|
|
|
|
assert_match(/RuntimeError: puke/, body)
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/not_found", headers: { "action_dispatch.show_exceptions" => true }, as: :json
|
2015-07-07 11:43:49 -04:00
|
|
|
assert_response 404
|
|
|
|
assert_no_match(/<body>/, body)
|
|
|
|
assert_equal "application/json", response.content_type
|
|
|
|
assert_match(/#{AbstractController::ActionNotFound.name}/, body)
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/method_not_allowed", headers: { "action_dispatch.show_exceptions" => true }, as: :json
|
2015-07-07 11:43:49 -04:00
|
|
|
assert_response 405
|
|
|
|
assert_no_match(/<body>/, body)
|
|
|
|
assert_equal "application/json", response.content_type
|
|
|
|
assert_match(/ActionController::MethodNotAllowed/, body)
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/unknown_http_method", headers: { "action_dispatch.show_exceptions" => true }, as: :json
|
2015-07-07 11:43:49 -04:00
|
|
|
assert_response 405
|
|
|
|
assert_no_match(/<body>/, body)
|
|
|
|
assert_equal "application/json", response.content_type
|
|
|
|
assert_match(/ActionController::UnknownHttpMethod/, body)
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/bad_request", headers: { "action_dispatch.show_exceptions" => true }, as: :json
|
2015-07-07 11:43:49 -04:00
|
|
|
assert_response 400
|
|
|
|
assert_no_match(/<body>/, body)
|
|
|
|
assert_equal "application/json", response.content_type
|
|
|
|
assert_match(/ActionController::BadRequest/, body)
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/parameter_missing", headers: { "action_dispatch.show_exceptions" => true }, as: :json
|
2015-07-07 11:43:49 -04:00
|
|
|
assert_response 400
|
|
|
|
assert_no_match(/<body>/, body)
|
|
|
|
assert_equal "application/json", response.content_type
|
|
|
|
assert_match(/ActionController::ParameterMissing/, body)
|
|
|
|
end
|
|
|
|
|
2016-05-07 21:44:38 -04:00
|
|
|
test "rescue with HTML format for HTML API request" do
|
2015-07-20 15:38:09 -04:00
|
|
|
@app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api)
|
2015-07-07 11:43:49 -04:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/index.html", headers: { "action_dispatch.show_exceptions" => true }
|
2015-07-07 11:43:49 -04:00
|
|
|
assert_response 500
|
2016-05-07 21:44:38 -04:00
|
|
|
assert_match(/<header>/, body)
|
|
|
|
assert_match(/<body>/, body)
|
|
|
|
assert_equal "text/html", response.content_type
|
|
|
|
assert_match(/puke/, body)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rescue with XML format for XML API requests" do
|
|
|
|
@app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api)
|
2015-07-07 11:43:49 -04:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/index.xml", headers: { "action_dispatch.show_exceptions" => true }
|
2015-07-07 11:43:49 -04:00
|
|
|
assert_response 500
|
|
|
|
assert_equal "application/xml", response.content_type
|
|
|
|
assert_match(/RuntimeError: puke/, body)
|
|
|
|
end
|
|
|
|
|
2016-05-07 21:44:38 -04:00
|
|
|
test "rescue with JSON format as fallback if API request format is not supported" do
|
|
|
|
begin
|
2016-08-06 12:54:50 -04:00
|
|
|
Mime::Type.register "text/wibble", :wibble
|
2016-05-07 21:44:38 -04:00
|
|
|
|
|
|
|
ActionDispatch::IntegrationTest.register_encoder(:wibble,
|
|
|
|
param_encoder: -> params { params })
|
|
|
|
|
|
|
|
@app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api)
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/index", headers: { "action_dispatch.show_exceptions" => true }, as: :wibble
|
2016-05-07 21:44:38 -04:00
|
|
|
assert_response 500
|
|
|
|
assert_equal "application/json", response.content_type
|
|
|
|
assert_match(/RuntimeError: puke/, body)
|
|
|
|
|
|
|
|
ensure
|
|
|
|
Mime::Type.unregister :wibble
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-01 15:15:42 -05:00
|
|
|
test "does not show filtered parameters" do
|
|
|
|
@app = DevelopmentApp
|
|
|
|
|
2016-10-28 23:05:58 -04:00
|
|
|
get "/", params: { "foo" => "bar" }, headers: { "action_dispatch.show_exceptions" => true,
|
2016-08-06 12:54:50 -04:00
|
|
|
"action_dispatch.parameter_filter" => [:foo] }
|
2011-12-01 15:15:42 -05:00
|
|
|
assert_response 500
|
|
|
|
assert_match(""foo"=>"[FILTERED]"", body)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "show registered original exception for wrapped exceptions" do
|
|
|
|
@app = DevelopmentApp
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/not_found_original_exception", headers: { "action_dispatch.show_exceptions" => true }
|
2011-12-01 15:15:42 -05:00
|
|
|
assert_response 404
|
|
|
|
assert_match(/AbstractController::ActionNotFound/, body)
|
|
|
|
end
|
|
|
|
|
2012-08-01 16:33:15 -04:00
|
|
|
test "named urls missing keys raise 500 level error" do
|
|
|
|
@app = DevelopmentApp
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/missing_keys", headers: { "action_dispatch.show_exceptions" => true }
|
2012-08-01 16:33:15 -04:00
|
|
|
assert_response 500
|
|
|
|
|
|
|
|
assert_match(/ActionController::UrlGenerationError/, body)
|
|
|
|
end
|
|
|
|
|
2011-12-01 15:15:42 -05:00
|
|
|
test "show the controller name in the diagnostics template when controller name is present" do
|
|
|
|
@app = DevelopmentApp
|
2015-01-04 04:35:06 -05:00
|
|
|
get("/runtime_error", headers: {
|
2016-08-06 12:54:50 -04:00
|
|
|
"action_dispatch.show_exceptions" => true,
|
|
|
|
"action_dispatch.request.parameters" => {
|
|
|
|
"action" => "show",
|
|
|
|
"id" => "unknown",
|
|
|
|
"controller" => "featured_tile"
|
2011-12-01 15:15:42 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
assert_response 500
|
2012-12-31 16:48:10 -05:00
|
|
|
assert_match(/RuntimeError\n\s+in FeaturedTileController/, body)
|
2011-12-01 15:15:42 -05:00
|
|
|
end
|
|
|
|
|
2014-12-01 17:45:33 -05:00
|
|
|
test "show formatted params" do
|
|
|
|
@app = DevelopmentApp
|
|
|
|
|
|
|
|
params = {
|
2016-08-06 12:54:50 -04:00
|
|
|
"id" => "unknown",
|
|
|
|
"someparam" => {
|
|
|
|
"foo" => "bar",
|
|
|
|
"abc" => "goo"
|
2014-12-01 17:45:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-04 04:35:06 -05:00
|
|
|
get("/runtime_error", headers: {
|
2016-08-06 12:54:50 -04:00
|
|
|
"action_dispatch.show_exceptions" => true,
|
|
|
|
"action_dispatch.request.parameters" => {
|
|
|
|
"action" => "show",
|
|
|
|
"controller" => "featured_tile"
|
2014-12-01 17:45:33 -05:00
|
|
|
}.merge(params)
|
|
|
|
})
|
|
|
|
assert_response 500
|
|
|
|
|
2017-07-01 16:09:13 -04:00
|
|
|
assert_includes(body, CGI.escapeHTML(PP.pp(params, "".dup, 200)))
|
2014-12-01 17:45:33 -05:00
|
|
|
end
|
|
|
|
|
2011-12-01 15:15:42 -05:00
|
|
|
test "sets the HTTP charset parameter" do
|
|
|
|
@app = DevelopmentApp
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/", headers: { "action_dispatch.show_exceptions" => true }
|
2011-12-01 15:15:42 -05:00
|
|
|
assert_equal "text/html; charset=utf-8", response.headers["Content-Type"]
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "uses logger from env" do
|
2011-12-01 15:15:42 -05:00
|
|
|
@app = DevelopmentApp
|
|
|
|
output = StringIO.new
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/", headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.logger" => Logger.new(output) }
|
2011-12-01 15:15:42 -05:00
|
|
|
assert_match(/puke/, output.rewind && output.read)
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "logs only what is necessary" do
|
2016-07-01 16:26:55 -04:00
|
|
|
@app = DevelopmentApp
|
|
|
|
io = StringIO.new
|
|
|
|
logger = ActiveSupport::Logger.new(io)
|
|
|
|
|
|
|
|
_old, ActionView::Base.logger = ActionView::Base.logger, logger
|
|
|
|
begin
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/", headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.logger" => logger }
|
2016-07-01 16:26:55 -04:00
|
|
|
ensure
|
|
|
|
ActionView::Base.logger = _old
|
|
|
|
end
|
|
|
|
|
|
|
|
output = io.rewind && io.read
|
|
|
|
lines = output.lines
|
|
|
|
|
|
|
|
# Other than the first three...
|
|
|
|
assert_equal([" \n", "RuntimeError (puke!):\n", " \n"], lines.slice!(0, 3))
|
|
|
|
lines.each do |line|
|
|
|
|
# .. all the remaining lines should be from the backtrace
|
|
|
|
assert_match(/:\d+:in /, line)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-28 15:54:16 -04:00
|
|
|
test "logs with non active support loggers" do
|
|
|
|
@app = DevelopmentApp
|
|
|
|
io = StringIO.new
|
|
|
|
logger = Logger.new(io)
|
|
|
|
|
|
|
|
_old, ActionView::Base.logger = ActionView::Base.logger, logger
|
|
|
|
begin
|
|
|
|
assert_nothing_raised do
|
|
|
|
get "/", headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.logger" => logger }
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
ActionView::Base.logger = _old
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/puke/, io.rewind && io.read)
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "uses backtrace cleaner from env" do
|
2011-12-01 15:15:42 -05:00
|
|
|
@app = DevelopmentApp
|
2015-09-05 10:58:21 -04:00
|
|
|
backtrace_cleaner = ActiveSupport::BacktraceCleaner.new
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
backtrace_cleaner.stub :clean, ["passed backtrace cleaner"] do
|
|
|
|
get "/", headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.backtrace_cleaner" => backtrace_cleaner }
|
2015-09-05 10:58:21 -04:00
|
|
|
assert_match(/passed backtrace cleaner/, body)
|
|
|
|
end
|
2011-12-01 15:15:42 -05:00
|
|
|
end
|
2011-12-13 14:32:39 -05:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "logs exception backtrace when all lines silenced" do
|
2011-12-13 14:32:39 -05:00
|
|
|
output = StringIO.new
|
|
|
|
backtrace_cleaner = ActiveSupport::BacktraceCleaner.new
|
|
|
|
backtrace_cleaner.add_silencer { true }
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
env = { "action_dispatch.show_exceptions" => true,
|
2016-08-06 12:54:50 -04:00
|
|
|
"action_dispatch.logger" => Logger.new(output),
|
2016-08-16 03:30:11 -04:00
|
|
|
"action_dispatch.backtrace_cleaner" => backtrace_cleaner }
|
2011-12-13 14:32:39 -05:00
|
|
|
|
2015-01-04 04:35:06 -05:00
|
|
|
get "/", headers: env
|
2011-12-16 00:00:20 -05:00
|
|
|
assert_operator((output.rewind && output.read).lines.count, :>, 10)
|
2011-12-13 14:32:39 -05:00
|
|
|
end
|
2014-01-30 09:33:49 -05:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "display backtrace when error type is SyntaxError" do
|
2014-01-30 09:33:49 -05:00
|
|
|
@app = DevelopmentApp
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/original_syntax_error", headers: { "action_dispatch.backtrace_cleaner" => ActiveSupport::BacktraceCleaner.new }
|
2014-01-30 09:33:49 -05:00
|
|
|
|
|
|
|
assert_response 500
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_select "#Application-Trace" do
|
|
|
|
assert_select "pre code", /syntax error, unexpected/
|
2014-01-30 09:33:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "display backtrace on template missing errors" do
|
2014-11-24 11:54:03 -05:00
|
|
|
@app = DevelopmentApp
|
|
|
|
|
2015-01-04 04:35:06 -05:00
|
|
|
get "/missing_template"
|
2014-11-24 11:54:03 -05:00
|
|
|
|
|
|
|
assert_select "header h1", /Template is missing/
|
|
|
|
|
|
|
|
assert_select "#container h2", /^Missing template/
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_select "#Application-Trace"
|
|
|
|
assert_select "#Framework-Trace"
|
|
|
|
assert_select "#Full-Trace"
|
2014-11-24 11:54:03 -05:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_select "h2", /Request/
|
2014-11-24 11:54:03 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "display backtrace when error type is SyntaxError wrapped by ActionView::Template::Error" do
|
2014-01-30 09:33:49 -05:00
|
|
|
@app = DevelopmentApp
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/syntax_error_into_view", headers: { "action_dispatch.backtrace_cleaner" => ActiveSupport::BacktraceCleaner.new }
|
2014-01-30 09:33:49 -05:00
|
|
|
|
|
|
|
assert_response 500
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_select "#Application-Trace" do
|
|
|
|
assert_select "pre code", /syntax error, unexpected/
|
2014-01-30 09:33:49 -05:00
|
|
|
end
|
|
|
|
end
|
2014-10-23 12:53:43 -04:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
test "debug exceptions app shows user code that caused the error in source view" do
|
2014-10-23 12:53:43 -04:00
|
|
|
@app = DevelopmentApp
|
2016-08-06 12:54:50 -04:00
|
|
|
Rails.stub :root, Pathname.new(".") do
|
2015-08-24 18:03:47 -04:00
|
|
|
cleaner = ActiveSupport::BacktraceCleaner.new.tap do |bc|
|
|
|
|
bc.add_silencer { |line| line =~ /method_that_raises/ }
|
|
|
|
bc.add_silencer { |line| line !~ %r{test/dispatch/debug_exceptions_test.rb} }
|
|
|
|
end
|
2014-10-23 12:53:43 -04:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/framework_raises", headers: { "action_dispatch.backtrace_cleaner" => cleaner }
|
2014-10-23 12:53:43 -04:00
|
|
|
|
2015-08-24 18:03:47 -04:00
|
|
|
# Assert correct error
|
|
|
|
assert_response 500
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_select "h2", /error in framework/
|
2014-10-23 12:53:43 -04:00
|
|
|
|
2015-08-24 18:03:47 -04:00
|
|
|
# assert source view line is the call to method_that_raises
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_select "div.source:not(.hidden)" do
|
|
|
|
assert_select "pre .line.active", /method_that_raises/
|
2015-08-24 18:03:47 -04:00
|
|
|
end
|
2014-10-23 12:53:43 -04:00
|
|
|
|
2015-08-24 18:03:47 -04:00
|
|
|
# assert first source view (hidden) that throws the error
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_select "div.source:first" do
|
|
|
|
assert_select "pre .line.active", /raise StandardError\.new/
|
2015-08-24 18:03:47 -04:00
|
|
|
end
|
2014-10-23 12:53:43 -04:00
|
|
|
|
2015-08-24 18:03:47 -04:00
|
|
|
# assert application trace refers to line that calls method_that_raises is first
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_select "#Application-Trace" do
|
|
|
|
assert_select "pre code a:first", %r{test/dispatch/debug_exceptions_test\.rb:\d+:in `call}
|
2015-08-24 18:03:47 -04:00
|
|
|
end
|
2014-10-23 12:53:43 -04:00
|
|
|
|
2015-11-12 11:06:44 -05:00
|
|
|
# assert framework trace that threw the error is first
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_select "#Framework-Trace" do
|
|
|
|
assert_select "pre code a:first", /method_that_raises/
|
2015-08-24 18:03:47 -04:00
|
|
|
end
|
2014-10-23 12:53:43 -04:00
|
|
|
end
|
|
|
|
end
|
2011-12-01 15:15:42 -05:00
|
|
|
end
|