提交 f9e14b02 编写于 作者: E Eugene Kenny

Reset CONTENT_LENGTH between test requests

If a POST request is followed by a GET request in a controller test, the
`rack.input` and `RAW_POST_DATA` headers from the first request will be
reset but the `CONTENT_LENGTH` header will leak, leading the request
object in the second request to incorrectly believe it has a body.
上级 ee6a431b
......@@ -604,6 +604,7 @@ def scrub_env!(env)
env.delete "action_dispatch.request.query_parameters"
env.delete "action_dispatch.request.request_parameters"
env["rack.input"] = StringIO.new
env.delete "CONTENT_LENGTH"
env.delete "RAW_POST_DATA"
env
end
......
......@@ -689,6 +689,14 @@ def test_raw_post_reset_between_post_requests
assert_equal "foo=baz", @request.raw_post
end
def test_content_length_reset_after_post_request
post :no_op, params: { foo: "bar" }
assert_not_equal 0, @request.content_length
get :no_op
assert_equal 0, @request.content_length
end
def test_path_is_kept_after_the_request
get :test_params, params: { id: "foo" }
assert_equal "/test_case_test/test/test_params/foo", @request.path
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册