diff options
Diffstat (limited to 'actionpack/test/dispatch/request_test.rb')
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 0dc8a2508e..e11b93b4f0 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -18,11 +18,11 @@ class BaseRequestTest < ActiveSupport::TestCase ActionDispatch::Http::URL.url_for(options) end - protected + private def stub_request(env = {}) ip_spoofing_check = env.key?(:ip_spoofing_check) ? env.delete(:ip_spoofing_check) : true @trusted_proxies ||= nil - ip_app = ActionDispatch::RemoteIp.new(Proc.new { }, ip_spoofing_check, @trusted_proxies) + ip_app = ActionDispatch::RemoteIp.new(Proc.new {}, ip_spoofing_check, @trusted_proxies) ActionDispatch::Http::URL.tld_length = env.delete(:tld_length) if env.key?(:tld_length) ip_app.call(env) @@ -94,13 +94,13 @@ class RequestIP < BaseRequestTest assert_equal "3.4.5.6", request.remote_ip request = stub_request "HTTP_X_FORWARDED_FOR" => "unknown,192.168.0.1" - assert_equal nil, request.remote_ip + assert_nil request.remote_ip request = stub_request "HTTP_X_FORWARDED_FOR" => "9.9.9.9, 3.4.5.6, 172.31.4.4, 10.0.0.1" assert_equal "3.4.5.6", request.remote_ip request = stub_request "HTTP_X_FORWARDED_FOR" => "not_ip_address" - assert_equal nil, request.remote_ip + assert_nil request.remote_ip end test "remote ip spoof detection" do @@ -154,7 +154,7 @@ class RequestIP < BaseRequestTest assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip request = stub_request "HTTP_X_FORWARDED_FOR" => "unknown,::1" - assert_equal nil, request.remote_ip + assert_nil request.remote_ip request = stub_request "HTTP_X_FORWARDED_FOR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334, fe80:0000:0000:0000:0202:b3ff:fe1e:8329, ::1, fc00::, fc01::, fdff" assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip @@ -163,7 +163,7 @@ class RequestIP < BaseRequestTest assert_equal "FE00::", request.remote_ip request = stub_request "HTTP_X_FORWARDED_FOR" => "not_ip_address" - assert_equal nil, request.remote_ip + assert_nil request.remote_ip end test "remote ip v6 spoof detection" do @@ -200,7 +200,7 @@ class RequestIP < BaseRequestTest assert_equal "3.4.5.6", request.remote_ip request = stub_request "HTTP_X_FORWARDED_FOR" => "67.205.106.73,unknown" - assert_equal nil, request.remote_ip + assert_nil request.remote_ip request = stub_request "HTTP_X_FORWARDED_FOR" => "9.9.9.9, 3.4.5.6, 10.0.0.1, 67.205.106.73" assert_equal "3.4.5.6", request.remote_ip @@ -222,7 +222,7 @@ class RequestIP < BaseRequestTest assert_equal "::1", request.remote_ip request = stub_request "HTTP_X_FORWARDED_FOR" => "unknown,fe80:0000:0000:0000:0202:b3ff:fe1e:8329" - assert_equal nil, request.remote_ip + assert_nil request.remote_ip request = stub_request "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329,2001:0db8:85a3:0000:0000:8a2e:0370:7334" assert_equal "2001:0db8:85a3:0000:0000:8a2e:0370:7334", request.remote_ip @@ -345,7 +345,7 @@ class RequestPort < BaseRequestTest test "optional port" do request = stub_request "HTTP_HOST" => "www.example.org:80" - assert_equal nil, request.optional_port + assert_nil request.optional_port request = stub_request "HTTP_HOST" => "www.example.org:8080" assert_equal 8080, request.optional_port @@ -537,7 +537,7 @@ class RequestCGI < BaseRequestTest assert_equal "Basic", request.auth_type assert_equal 0, request.content_length - assert_equal nil, request.content_mime_type + assert_nil request.content_mime_type assert_equal "CGI/1.1", request.gateway_interface assert_equal "*/*", request.accept assert_equal "UTF-8", request.accept_charset @@ -581,7 +581,7 @@ class RequestCookie < BaseRequestTest # some Nokia phone browsers omit the space after the semicolon separator. # some developers have grown accustomed to using comma in cookie values. - request = stub_request("HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes") + request = stub_request("HTTP_COOKIE" => "_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes") assert_equal "c84ace847", request.cookies["_session_id"], request.cookies.inspect assert_equal "yes", request.cookies["is_admin"], request.cookies.inspect end @@ -596,7 +596,7 @@ class RequestParamsParsing < BaseRequestTest "rack.input" => StringIO.new("flamenco=love") ) - assert_equal({"flamenco"=> "love"}, request.request_parameters) + assert_equal({ "flamenco" => "love" }, request.request_parameters) end test "doesnt interpret request uri as query string when missing" do @@ -774,8 +774,8 @@ class RequestMethod < BaseRequestTest ensure # Reset original acronym set ActiveSupport::Inflector.inflections do |inflect| - inflect.send(:instance_variable_set,"@acronyms",existing_acrnoyms) - inflect.send(:instance_variable_set,"@acronym_regex",existing_acrnoym_regex) + inflect.send(:instance_variable_set, "@acronyms", existing_acrnoyms) + inflect.send(:instance_variable_set, "@acronym_regex", existing_acrnoym_regex) end end end @@ -784,21 +784,21 @@ end class RequestFormat < BaseRequestTest test "xml format" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :xml}) do + assert_called(request, :parameters, times: 2, returns: { format: :xml }) do assert_equal Mime[:xml], request.format end end test "xhtml format" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :xhtml}) do + assert_called(request, :parameters, times: 2, returns: { format: :xhtml }) do assert_equal Mime[:html], request.format end end test "txt format" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :txt}) do + assert_called(request, :parameters, times: 2, returns: { format: :txt }) do assert_equal Mime[:text], request.format end end @@ -817,14 +817,14 @@ class RequestFormat < BaseRequestTest test "can override format with parameter negative" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :txt}) do + assert_called(request, :parameters, times: 2, returns: { format: :txt }) do assert !request.format.xml? end end test "can override format with parameter positive" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :xml}) do + assert_called(request, :parameters, times: 2, returns: { format: :xml }) do assert request.format.xml? end end @@ -852,21 +852,21 @@ class RequestFormat < BaseRequestTest test "formats format:text with accept header" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :txt}) do + assert_called(request, :parameters, times: 2, returns: { format: :txt }) do assert_equal [Mime[:text]], request.formats end end test "formats format:unknown with accept header" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :unknown}) do + assert_called(request, :parameters, times: 2, returns: { format: :unknown }) do assert_instance_of Mime::NullType, request.format end end test "format is not nil with unknown format" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :hello}) do + assert_called(request, :parameters, times: 2, returns: { format: :hello }) do assert request.format.nil? assert_not request.format.html? assert_not request.format.xml? @@ -921,7 +921,7 @@ class RequestFormat < BaseRequestTest request = stub_request "HTTP_ACCEPT" => "application/xml", "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" - assert_called(request, :parameters, times: 2, returns: {format: :json}) do + assert_called(request, :parameters, times: 2, returns: { format: :json }) do assert_equal [ Mime[:json] ], request.formats end ensure @@ -957,7 +957,7 @@ class RequestMimeType < BaseRequestTest end test "no content type" do - assert_equal nil, stub_request.content_mime_type + assert_nil stub_request.content_mime_type end test "content type is XML" do @@ -978,7 +978,7 @@ class RequestMimeType < BaseRequestTest "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" ) - assert_equal nil, request.negotiate_mime([Mime[:xml], Mime[:json]]) + assert_nil request.negotiate_mime([Mime[:xml], Mime[:json]]) assert_equal Mime[:html], request.negotiate_mime([Mime[:xml], Mime[:html]]) assert_equal Mime[:html], request.negotiate_mime([Mime[:xml], Mime::ALL]) end @@ -997,11 +997,11 @@ class RequestParameters < BaseRequestTest test "parameters" do request = stub_request - assert_called(request, :request_parameters, times: 2, returns: {"foo" => 1}) do - assert_called(request, :query_parameters, times: 2, returns: {"bar" => 2}) do - assert_equal({"foo" => 1, "bar" => 2}, request.parameters) - assert_equal({"foo" => 1}, request.request_parameters) - assert_equal({"bar" => 2}, request.query_parameters) + assert_called(request, :request_parameters, times: 2, returns: { "foo" => 1 }) do + assert_called(request, :query_parameters, times: 2, returns: { "bar" => 2 }) do + assert_equal({ "foo" => 1, "bar" => 2 }, request.parameters) + assert_equal({ "foo" => 1 }, request.request_parameters) + assert_equal({ "bar" => 2 }, request.query_parameters) end end end @@ -1072,14 +1072,14 @@ end class RequestParameterFilter < BaseRequestTest test "process parameter filter" do test_hashes = [ - [{"foo"=>"bar"},{"foo"=>"bar"},%w'food'], - [{"foo"=>"bar"},{"foo"=>"[FILTERED]"},%w'foo'], - [{"foo"=>"bar", "bar"=>"foo"},{"foo"=>"[FILTERED]", "bar"=>"foo"},%w'foo baz'], - [{"foo"=>"bar", "baz"=>"foo"},{"foo"=>"[FILTERED]", "baz"=>"[FILTERED]"},%w'foo baz'], - [{"bar"=>{"foo"=>"bar","bar"=>"foo"}},{"bar"=>{"foo"=>"[FILTERED]","bar"=>"foo"}},%w'fo'], - [{"foo"=>{"foo"=>"bar","bar"=>"foo"}},{"foo"=>"[FILTERED]"},%w'f banana'], - [{"deep"=>{"cc"=>{"code"=>"bar","bar"=>"foo"},"ss"=>{"code"=>"bar"}}},{"deep"=>{"cc"=>{"code"=>"[FILTERED]","bar"=>"foo"},"ss"=>{"code"=>"bar"}}},%w'deep.cc.code'], - [{"baz"=>[{"foo"=>"baz"}, "1"]}, {"baz"=>[{"foo"=>"[FILTERED]"}, "1"]}, [/foo/]]] + [{ "foo" => "bar" }, { "foo" => "bar" }, %w'food'], + [{ "foo" => "bar" }, { "foo" => "[FILTERED]" }, %w'foo'], + [{ "foo" => "bar", "bar" => "foo" }, { "foo" => "[FILTERED]", "bar" => "foo" }, %w'foo baz'], + [{ "foo" => "bar", "baz" => "foo" }, { "foo" => "[FILTERED]", "baz" => "[FILTERED]" }, %w'foo baz'], + [{ "bar" => { "foo" => "bar", "bar" => "foo" } }, { "bar" => { "foo" => "[FILTERED]", "bar" => "foo" } }, %w'fo'], + [{ "foo" => { "foo" => "bar", "bar" => "foo" } }, { "foo" => "[FILTERED]" }, %w'f banana'], + [{ "deep" => { "cc" => { "code" => "bar", "bar" => "foo" }, "ss" => { "code" => "bar" } } }, { "deep" => { "cc" => { "code" => "[FILTERED]", "bar" => "foo" }, "ss" => { "code" => "bar" } } }, %w'deep.cc.code'], + [{ "baz" => [{ "foo" => "baz" }, "1"] }, { "baz" => [{ "foo" => "[FILTERED]" }, "1"] }, [/foo/]]] test_hashes.each do |before_filter, after_filter, filter_words| parameter_filter = ActionDispatch::Http::ParameterFilter.new(filter_words) @@ -1091,8 +1091,8 @@ class RequestParameterFilter < BaseRequestTest } parameter_filter = ActionDispatch::Http::ParameterFilter.new(filter_words) - before_filter["barg"] = {:bargain=>"gain", "blah"=>"bar", "bar"=>{"bargain"=>{"blah"=>"foo"}}} - after_filter["barg"] = {:bargain=>"niag", "blah"=>"[FILTERED]", "bar"=>{"bargain"=>{"blah"=>"[FILTERED]"}}} + before_filter["barg"] = { :bargain => "gain", "blah" => "bar", "bar" => { "bargain" => { "blah" => "foo" } } } + after_filter["barg"] = { :bargain => "niag", "blah" => "[FILTERED]", "bar" => { "bargain" => { "blah" => "[FILTERED]" } } } assert_equal after_filter, parameter_filter.filter(before_filter) end @@ -1192,7 +1192,7 @@ class RequestEtag < BaseRequestTest test "doesn't match absent If-None-Match" do request = stub_request - assert_equal nil, request.if_none_match + assert_nil request.if_none_match assert_equal [], request.if_none_match_etags assert_not request.etag_matches?("foo") |