From 59008016a267c2a9f6e26925d2da1e490692f193 Mon Sep 17 00:00:00 2001 From: Carl Zulauf Date: Thu, 29 Dec 2016 11:09:24 -0600 Subject: [PATCH 1/3] Minimal resolution of EOFError in MethodOverride middleware --- lib/rack/method_override.rb | 2 +- test/spec_method_override.rb | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/rack/method_override.rb b/lib/rack/method_override.rb index f56377711..244214b10 100644 --- a/lib/rack/method_override.rb +++ b/lib/rack/method_override.rb @@ -37,7 +37,7 @@ def allowed_methods def method_override_param(req) req.POST[METHOD_OVERRIDE_PARAM_KEY] - rescue Utils::InvalidParameterError, Utils::ParameterTypeError + rescue Utils::InvalidParameterError, Utils::ParameterTypeError, EOFError end end end diff --git a/test/spec_method_override.rb b/test/spec_method_override.rb index 14ace0b17..9352e399f 100644 --- a/test/spec_method_override.rb +++ b/test/spec_method_override.rb @@ -66,10 +66,7 @@ def app "CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x", "CONTENT_LENGTH" => input.size.to_s, :method => "POST", :input => input) - begin - app.call env - rescue EOFError - end + app.call env env["REQUEST_METHOD"].must_equal "POST" end From db45a93daab59ddee520890d104701bf089ccd2b Mon Sep 17 00:00:00 2001 From: Carl Zulauf Date: Thu, 29 Dec 2016 11:10:16 -0600 Subject: [PATCH 2/3] Resolve undefined constant test failure by loading constant --- test/spec_webrick.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/spec_webrick.rb b/test/spec_webrick.rb index 469ae62ac..eff64116d 100644 --- a/test/spec_webrick.rb +++ b/test/spec_webrick.rb @@ -1,5 +1,6 @@ require 'minitest/autorun' require 'rack/mock' +require 'concurrent/utility/native_integer' require 'concurrent/atomic/count_down_latch' require File.expand_path('../testrequest', __FILE__) From ea8479d606a6afda08ecb89057e5593f04fd5f3b Mon Sep 17 00:00:00 2001 From: Carl Zulauf Date: Thu, 29 Dec 2016 11:32:38 -0600 Subject: [PATCH 3/3] Write MethodOverride errors to RACK_ERRORS --- lib/rack/method_override.rb | 5 ++++- test/spec_method_override.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/rack/method_override.rb b/lib/rack/method_override.rb index 244214b10..06df21f7b 100644 --- a/lib/rack/method_override.rb +++ b/lib/rack/method_override.rb @@ -37,7 +37,10 @@ def allowed_methods def method_override_param(req) req.POST[METHOD_OVERRIDE_PARAM_KEY] - rescue Utils::InvalidParameterError, Utils::ParameterTypeError, EOFError + rescue Utils::InvalidParameterError, Utils::ParameterTypeError + req.get_header(RACK_ERRORS).puts "Invalid or incomplete POST params" + rescue EOFError + req.get_header(RACK_ERRORS).puts "Bad request content body" end end end diff --git a/test/spec_method_override.rb b/test/spec_method_override.rb index 9352e399f..bb72af9f3 100644 --- a/test/spec_method_override.rb +++ b/test/spec_method_override.rb @@ -71,6 +71,22 @@ def app env["REQUEST_METHOD"].must_equal "POST" end + it "writes error to RACK_ERRORS when given invalid multipart form data" do + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size.to_s, + Rack::RACK_ERRORS => StringIO.new, + :method => "POST", :input => input) + Rack::MethodOverride.new(proc { [200, {"Content-Type" => "text/plain"}, []] }).call env + + env[Rack::RACK_ERRORS].rewind + env[Rack::RACK_ERRORS].read.must_match /Bad request content body/ + end + it "not modify REQUEST_METHOD for POST requests when the params are unparseable" do env = Rack::MockRequest.env_for("/", :method => "POST", :input => "(%bad-params%)") app.call env