File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) )
You can’t perform that action at this time.
0 commit comments