aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJeremy Kemper <jeremykemper@gmail.com>2014-08-21 21:37:58 -0700
committerJeremy Kemper <jeremykemper@gmail.com>2014-08-21 21:37:58 -0700
commit7fce2164036dc38e1e3904479c29d5abfe1e7be5 (patch)
tree6aae0ccc48efec8534f480152f6ba500d53e09a9 /railties
parent0e4b2174462de1b36ab5ddc60c893109f826d64b (diff)
parentf9a84bb2361d7ec2147ca9e104f66ceb159a4039 (diff)
downloadrails-7fce2164036dc38e1e3904479c29d5abfe1e7be5.tar.gz
rails-7fce2164036dc38e1e3904479c29d5abfe1e7be5.tar.bz2
rails-7fce2164036dc38e1e3904479c29d5abfe1e7be5.zip
Merge pull request #16604 from saarons/clean-remote-ip-middleware
ActionDispatch::RemoteIp accept IPAddr matches for trusted proxies
Diffstat (limited to 'railties')
-rw-r--r--railties/test/application/middleware/remote_ip_test.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/railties/test/application/middleware/remote_ip_test.rb b/railties/test/application/middleware/remote_ip_test.rb
index 946b82eeb3..97d5b5c698 100644
--- a/railties/test/application/middleware/remote_ip_test.rb
+++ b/railties/test/application/middleware/remote_ip_test.rb
@@ -1,3 +1,4 @@
+require 'ipaddr'
require 'isolation/abstract_unit'
require 'active_support/key_generator'
@@ -53,12 +54,25 @@ module ApplicationTests
end
end
+ test "remote_ip works with HTTP_X_FORWARDED_FOR" do
+ make_basic_app
+ assert_equal "4.2.42.42", remote_ip("REMOTE_ADDR" => "1.1.1.1", "HTTP_X_FORWARDED_FOR" => "4.2.42.42")
+ end
+
test "the user can set trusted proxies" do
make_basic_app do |app|
app.config.action_dispatch.trusted_proxies = /^4\.2\.42\.42$/
end
- assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "4.2.42.42,1.1.1.1")
+ assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "1.1.1.1", "HTTP_X_FORWARDED_FOR" => "4.2.42.42")
+ end
+
+ test "the user can set trusted proxies with an IPAddr argument" do
+ make_basic_app do |app|
+ app.config.action_dispatch.trusted_proxies = IPAddr.new('4.2.42.0/24')
+ end
+
+ assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "1.1.1.1", "HTTP_X_FORWARDED_FOR" => "10.0.0.0,4.2.42.42")
end
end
end