Merge pull request #48956 from skipkayhil/hm-rack-lint-show-exceptions-failsafe

Add test coverage for ShowExceptions failsafe
This commit is contained in:
Guillermo Iguaran 2023-08-18 16:08:41 -07:00 committed by GitHub
commit 5a21634407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -54,7 +54,7 @@ module ActionDispatch
rescue Exception => failsafe_error
$stderr.puts "Error during failsafe response: #{failsafe_error}\n #{failsafe_error.backtrace * "\n "}"
[500, { "Content-Type" => "text/plain; charset=utf-8" },
[500, { Rack::CONTENT_TYPE => "text/plain; charset=utf-8" },
["500 Internal Server Error\n" \
"If you are the administrator of this website, then please read this web " \
"application's log file and/or the web server's log file to find out what " \

View File

@ -135,6 +135,18 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
assert_equal("{\"status\":400,\"error\":\"Bad Request\"}", body)
end
test "failsafe prevents raising if exceptions_app raises" do
old_stderr, $stderr = $stderr, StringIO.new
@app = build_app(->(_) { raise })
get "/"
assert_response 500
assert_match(/500 Internal Server Error/, body)
ensure
$stderr = old_stderr
end
private
def build_app(exceptions_app = nil)
exceptions_app ||= ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")