Skip to content

Commit e3027ef

Browse files
committed
Add failing test
1 parent 501a45d commit e3027ef

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

test/uri/test_generic.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,37 @@ def test_find_proxy_no_proxy
972972
end
973973
end
974974

975+
def test_find_proxy_no_proxy_not_resolving_hostname
976+
getaddress = IPSocket.method(:getaddress)
977+
resolved_hosts = []
978+
IPSocket.singleton_class.class_eval do
979+
undef getaddress
980+
define_method(:getaddress) do |host|
981+
resolved_hosts << host
982+
host
983+
end
984+
end
985+
986+
with_proxy_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'example.org') {|env|
987+
assert_nil(URI("http://example.org/").find_proxy(env))
988+
assert_nil(URI("http://www.example.org/").find_proxy(env))
989+
}
990+
with_proxy_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'.example.org') {|env|
991+
assert_nil(URI("http://www.example.org/").find_proxy(env))
992+
}
993+
with_proxy_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'192.0.2.2') {|env|
994+
assert_nil(URI("http://192.0.2.2/").find_proxy(env))
995+
}
996+
997+
assert_equal([], resolved_hosts,
998+
"IPSocket.getaddress should not be called when hostname matches no_proxy")
999+
ensure
1000+
IPSocket.singleton_class.class_eval do
1001+
undef getaddress
1002+
define_method(:getaddress, getaddress)
1003+
end
1004+
end
1005+
9751006
def test_find_proxy_no_proxy_cidr
9761007
with_proxy_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'192.0.2.0/24') {|env|
9771008
assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.1.1/").find_proxy(env))

0 commit comments

Comments
 (0)