mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #16098 from tgxworld/fixes_to_request_test
Fixes to request method test.
This commit is contained in:
commit
fe6f436dd9
1 changed files with 14 additions and 22 deletions
|
@ -639,12 +639,14 @@ class RequestProtocol < BaseRequestTest
|
||||||
end
|
end
|
||||||
|
|
||||||
class RequestMethod < BaseRequestTest
|
class RequestMethod < BaseRequestTest
|
||||||
test "request methods" do
|
test "method returns environment's request method when it has not been
|
||||||
[:post, :get, :patch, :put, :delete].each do |method|
|
overriden by middleware".squish do
|
||||||
request = stub_request('REQUEST_METHOD' => method.to_s.upcase)
|
|
||||||
|
|
||||||
assert_equal method.to_s.upcase, request.method
|
ActionDispatch::Request::HTTP_METHODS.each do |method|
|
||||||
assert_equal method, request.method_symbol
|
request = stub_request('REQUEST_METHOD' => method)
|
||||||
|
|
||||||
|
assert_equal method, request.method
|
||||||
|
assert_equal method.underscore.to_sym, request.method_symbol
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -654,28 +656,18 @@ class RequestMethod < BaseRequestTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "allow method hacking on post" do
|
test "method returns original value of environment request method on POST" do
|
||||||
%w(GET OPTIONS PATCH PUT POST DELETE).each do |method|
|
request = stub_request('rack.methodoverride.original_method' => 'POST')
|
||||||
request = stub_request 'REQUEST_METHOD' => method.to_s.upcase
|
assert_equal 'POST', request.method
|
||||||
|
|
||||||
assert_equal(method == "HEAD" ? "GET" : method, request.method)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "invalid method hacking on post raises exception" do
|
test "method raises exception on invalid HTTP method" do
|
||||||
assert_raise(ActionController::UnknownHttpMethod) do
|
assert_raise(ActionController::UnknownHttpMethod) do
|
||||||
stub_request('REQUEST_METHOD' => '_RANDOM_METHOD').request_method
|
stub_request('rack.methodoverride.original_method' => '_RANDOM_METHOD').method
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
test "restrict method hacking" do
|
assert_raise(ActionController::UnknownHttpMethod) do
|
||||||
[:get, :patch, :put, :delete].each do |method|
|
stub_request('REQUEST_METHOD' => '_RANDOM_METHOD').method
|
||||||
request = stub_request(
|
|
||||||
'action_dispatch.request.request_parameters' => { :_method => 'put' },
|
|
||||||
'REQUEST_METHOD' => method.to_s.upcase
|
|
||||||
)
|
|
||||||
|
|
||||||
assert_equal method.to_s.upcase, request.method
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue