summaryrefslogtreecommitdiff
path: root/test/net
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-20 01:56:21 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-20 01:56:21 +0000
commit9416becda4592f7884460a054fe12b7761f6f055 (patch)
treeb8bf90896acfb3610e1f0665e50cf31fbbd3f209 /test/net
parentf35b1d0633a6423f1281fb3c2b29aa522090976f (diff)
* lib/net/http.rb: Net::HTTP now automatically detects and uses
proxies from the environment. A proxy may also be specified as before. Net::HTTP::Proxy still creates anonymous classes, but these classes are only used to store configuration information. When an HTTP instance is created the configuration is now copied. Additionally, Net::HTTP::ProxyDelta is no longer used by Net::HTTP [Feature #6546] * lib/open-uri.rb: Moved URI::Generic#find_proxy to uri/generic. * lib/uri/generic.rb: Imported find_proxy from open-uri. * test/open-uri/test_open-uri.rb: Moved proxy-discovery tests to URI. * test/uri/test_generic.rb: Imported proxy-discovery tests from open-uri. * test/net/http/test_http.rb: Added tests for proxy behavior. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/net')
-rw-r--r--test/net/http/test_http.rb161
1 files changed, 161 insertions, 0 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb
index e390cf1e8d..df71c2add9 100644
--- a/test/net/http/test_http.rb
+++ b/test/net/http/test_http.rb
@@ -5,6 +5,167 @@ require 'net/http'
require 'stringio'
require_relative 'utils'
+class TestNetHTTP < Test::Unit::TestCase
+
+ def test_class_Proxy
+ no_proxy_class = Net::HTTP.Proxy nil
+
+ assert_equal Net::HTTP, no_proxy_class
+
+ proxy_class = Net::HTTP.Proxy 'proxy.example', 8000, 'user', 'pass'
+
+ refute_equal Net::HTTP, proxy_class
+
+ assert_operator proxy_class, :<, Net::HTTP
+
+ assert_equal 'proxy.example', proxy_class.proxy_address
+ assert_equal 8000, proxy_class.proxy_port
+ assert_equal 'user', proxy_class.proxy_user
+ assert_equal 'pass', proxy_class.proxy_pass
+
+ http = proxy_class.new 'example'
+
+ refute http.proxy_from_env?
+ end
+
+ def test_class_Proxy_from_ENV
+ clean_http_proxy_env do
+ ENV['http_proxy'] = 'http://proxy.example:8000'
+
+ # These are ignored on purpose. See Bug 4388 and Feature 6546
+ ENV['http_proxy_user'] = 'user'
+ ENV['http_proxy_pass'] = 'pass'
+
+ proxy_class = Net::HTTP.Proxy :ENV
+
+ refute_equal Net::HTTP, proxy_class
+
+ assert_operator proxy_class, :<, Net::HTTP
+
+ assert_nil proxy_class.proxy_address
+ assert_nil proxy_class.proxy_user
+ assert_nil proxy_class.proxy_pass
+
+ refute_equal 8000, proxy_class.proxy_port
+
+ http = proxy_class.new 'example'
+
+ assert http.proxy_from_env?
+ end
+ end
+
+ def test_edit_path
+ http = Net::HTTP.new 'example', nil, nil
+
+ edited = http.send :edit_path, '/path'
+
+ assert_equal '/path', edited
+
+ http.use_ssl = true
+
+ edited = http.send :edit_path, '/path'
+
+ assert_equal '/path', edited
+ end
+
+ def test_edit_path_proxy
+ http = Net::HTTP.new 'example', nil, 'proxy.example'
+
+ edited = http.send :edit_path, '/path'
+
+ assert_equal 'http://example/path', edited
+
+ http.use_ssl = true
+
+ edited = http.send :edit_path, '/path'
+
+ assert_equal '/path', edited
+ end
+
+ def test_proxy_address
+ http = Net::HTTP.new 'example', nil, 'proxy.example'
+
+ assert_equal 'proxy.example', http.proxy_address
+ end
+
+ def test_proxy_address_ENV
+ clean_http_proxy_env do
+ ENV['http_proxy'] = 'http://proxy.example:8000'
+
+ http = Net::HTTP.new 'example'
+
+ assert_equal 'proxy.example', http.proxy_address
+ end
+ end
+
+ def test_proxy_eh_no_proxy
+ clean_http_proxy_env do
+ refute Net::HTTP.new('example', nil, nil).proxy?
+ end
+ end
+
+ def test_proxy_eh_ENV
+ clean_http_proxy_env do
+ ENV['http_proxy'] = 'http://proxy.example:8000'
+
+ http = Net::HTTP.new 'example'
+
+ assert http.proxy?
+ end
+ end
+
+ def test_proxy_eh_ENV_none_set
+ clean_http_proxy_env do
+ refute Net::HTTP.new('example').proxy?
+ end
+ end
+
+ def test_proxy_eh_ENV_no_proxy
+ clean_http_proxy_env do
+ ENV['http_proxy'] = 'http://proxy.example:8000'
+ ENV['no_proxy'] = 'example'
+
+ refute Net::HTTP.new('example').proxy?
+ end
+ end
+
+ def test_proxy_port
+ http = Net::HTTP.new 'exmaple', nil, 'proxy.example', 8000
+
+ assert_equal 8000, http.proxy_port
+ end
+
+ def test_proxy_port_ENV
+ clean_http_proxy_env do
+ ENV['http_proxy'] = 'http://proxy.example:8000'
+
+ http = Net::HTTP.new 'example'
+
+ assert_equal 8000, http.proxy_port
+ end
+ end
+
+ def clean_http_proxy_env
+ orig = {
+ 'http_proxy' => ENV['http_proxy'],
+ 'http_proxy_user' => ENV['http_proxy_user'],
+ 'http_proxy_pass' => ENV['http_proxy_pass'],
+ 'no_proxy' => ENV['no_proxy'],
+ }
+
+ orig.each_key do |key|
+ ENV.delete key
+ end
+
+ yield
+ ensure
+ orig.each do |key, value|
+ ENV[key] = value
+ end
+ end
+
+end
+
module TestNetHTTP_version_1_1_methods
def test_s_get