Skip to content

Commit

Permalink
Fix deprecation warning on Actionpack request test
Browse files Browse the repository at this point in the history
The way this test initializes `ActionDispatch::RemoteIp` has been
deprecated in rails#40789. This makes the test append to the existing
trusted proxy list instead of assigning a single value.
  • Loading branch information
csutter committed Mar 26, 2021
1 parent 30ef292 commit eab5a38
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions actionpack/test/dispatch/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def url_for(options = {})
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)
@additional_trusted_proxy ||= nil
trusted_proxies = ActionDispatch::RemoteIp::TRUSTED_PROXIES + [@additional_trusted_proxy]
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)
Expand Down Expand Up @@ -199,7 +200,7 @@ class RequestIP < BaseRequestTest
end

test "remote ip with user specified trusted proxies String" do
@trusted_proxies = "67.205.106.73"
@additional_trusted_proxy = "67.205.106.73"

request = stub_request "REMOTE_ADDR" => "3.4.5.6",
"HTTP_X_FORWARDED_FOR" => "67.205.106.73"
Expand All @@ -221,7 +222,7 @@ class RequestIP < BaseRequestTest
end

test "remote ip v6 with user specified trusted proxies String" do
@trusted_proxies = "fe80:0000:0000:0000:0202:b3ff:fe1e:8329"
@additional_trusted_proxy = "fe80:0000:0000:0000:0202:b3ff:fe1e:8329"

request = stub_request "REMOTE_ADDR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329"
Expand All @@ -243,7 +244,7 @@ class RequestIP < BaseRequestTest
end

test "remote ip with user specified trusted proxies Regexp" do
@trusted_proxies = /^67\.205\.106\.73$/i
@additional_trusted_proxy = /^67\.205\.106\.73$/i

request = stub_request "REMOTE_ADDR" => "67.205.106.73",
"HTTP_X_FORWARDED_FOR" => "3.4.5.6"
Expand All @@ -254,7 +255,7 @@ class RequestIP < BaseRequestTest
end

test "remote ip v6 with user specified trusted proxies Regexp" do
@trusted_proxies = /^fe80:0000:0000:0000:0202:b3ff:fe1e:8329$/i
@additional_trusted_proxy = /^fe80:0000:0000:0000:0202:b3ff:fe1e:8329$/i

request = stub_request "REMOTE_ADDR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329"
Expand Down

0 comments on commit eab5a38

Please sign in to comment.