mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Adding a call to logger from params_parser to give detailed debug information when invalid xml or json is posted
[#2481 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
parent
911acc10de
commit
679128da58
3 changed files with 47 additions and 6 deletions
|
@ -47,6 +47,8 @@ module ActionDispatch
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
rescue Exception => e # YAML, XML or Ruby code block errors
|
rescue Exception => e # YAML, XML or Ruby code block errors
|
||||||
|
logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"
|
||||||
|
|
||||||
raise
|
raise
|
||||||
{ "body" => request.raw_post,
|
{ "body" => request.raw_post,
|
||||||
"content_type" => request.content_type,
|
"content_type" => request.content_type,
|
||||||
|
@ -67,5 +69,9 @@ module ActionDispatch
|
||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def logger
|
||||||
|
defined?(Rails.logger) ? Rails.logger : Logger.new($stderr)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,16 +30,36 @@ class JsonParamsParsingTest < ActionController::IntegrationTest
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logs error if parsing unsuccessful" do
|
||||||
|
with_test_routing do
|
||||||
|
begin
|
||||||
|
$stderr = StringIO.new
|
||||||
|
json = "[\"person]\": {\"name\": \"David\"}}"
|
||||||
|
post "/parse", json, {'CONTENT_TYPE' => 'application/json'}
|
||||||
|
assert_response :error
|
||||||
|
$stderr.rewind && err = $stderr.read
|
||||||
|
assert err =~ /Error occurred while parsing request parameters/
|
||||||
|
ensure
|
||||||
|
$stderr = STDERR
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def assert_parses(expected, actual, headers = {})
|
def assert_parses(expected, actual, headers = {})
|
||||||
with_routing do |set|
|
with_test_routing do
|
||||||
set.draw do |map|
|
|
||||||
map.connect ':action', :controller => "json_params_parsing_test/test"
|
|
||||||
end
|
|
||||||
|
|
||||||
post "/parse", actual, headers
|
post "/parse", actual, headers
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
assert_equal(expected, TestController.last_request_parameters)
|
assert_equal(expected, TestController.last_request_parameters)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_test_routing
|
||||||
|
with_routing do |set|
|
||||||
|
set.draw do |map|
|
||||||
|
map.connect ':action', :controller => "json_params_parsing_test/test"
|
||||||
|
end
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,21 @@ class XmlParamsParsingTest < ActionController::IntegrationTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logs error if parsing unsuccessful" do
|
||||||
|
with_test_routing do
|
||||||
|
begin
|
||||||
|
$stderr = StringIO.new
|
||||||
|
xml = "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></pineapple>"
|
||||||
|
post "/parse", xml, default_headers
|
||||||
|
assert_response :error
|
||||||
|
$stderr.rewind && err = $stderr.read
|
||||||
|
assert err =~ /Error occurred while parsing request parameters/
|
||||||
|
ensure
|
||||||
|
$stderr = STDERR
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "parses multiple files" do
|
test "parses multiple files" do
|
||||||
xml = <<-end_body
|
xml = <<-end_body
|
||||||
<person>
|
<person>
|
||||||
|
|
Loading…
Reference in a new issue