From ffad7d737c0cec88ccb5c3ce59e59a2b7d6647ac Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 12 Sep 2009 03:47:18 +0000 Subject: refined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/test_open-uri.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/test_open-uri.rb b/test/test_open-uri.rb index 2e7053fef7..85f2880dba 100644 --- a/test/test_open-uri.rb +++ b/test/test_open-uri.rb @@ -6,13 +6,17 @@ require 'zlib' class TestOpenURI < Test::Unit::TestCase + NullLog = Object.new + def NullLog.<<(arg) + end + def with_http Dir.mktmpdir {|dr| srv = WEBrick::HTTPServer.new({ :DocumentRoot => dr, :ServerType => Thread, - :Logger => WEBrick::Log.new(StringIO.new("")), - :AccessLog => [[StringIO.new(""), ""]], + :Logger => WEBrick::Log.new(NullLog), + :AccessLog => [[NullLog, ""]], :BindAddress => '127.0.0.1', :Port => 0}) _, port, _, host = srv.listeners[0].addr @@ -116,8 +120,8 @@ class TestOpenURI < Test::Unit::TestCase with_http {|srv, dr, url| prxy = WEBrick::HTTPProxyServer.new({ :ServerType => Thread, - :Logger => WEBrick::Log.new(StringIO.new("")), - :AccessLog => [[StringIO.new(""), ""]], + :Logger => WEBrick::Log.new(NullLog), + :AccessLog => [[NullLog, ""]], :BindAddress => '127.0.0.1', :Port => 0}) _, p_port, _, p_host = prxy.listeners[0].addr @@ -149,8 +153,8 @@ class TestOpenURI < Test::Unit::TestCase with_http {|srv, dr, url| prxy = WEBrick::HTTPProxyServer.new({ :ServerType => Thread, - :Logger => WEBrick::Log.new(StringIO.new("")), - :AccessLog => [[StringIO.new(""), ""]], + :Logger => WEBrick::Log.new(NullLog), + :AccessLog => [[NullLog, ""]], :ProxyAuthProc => lambda {|req, res| if req["Proxy-Authorization"] != "Basic #{['user:pass'].pack('m').chomp}" raise WEBrick::HTTPStatus::ProxyAuthenticationRequired @@ -333,8 +337,9 @@ class TestOpenURI < Test::Unit::TestCase end end + # 192.0.2.0/24 is TEST-NET. [RFC3330] + def test_find_proxy - # 192.0.2.0/24 is TEST-NET. RFC3330 assert_nil(URI("http://192.0.2.1/").find_proxy) assert_nil(URI("ftp://192.0.2.1/").find_proxy) with_env('http_proxy'=>'http://127.0.0.1:8080') { @@ -348,6 +353,9 @@ class TestOpenURI < Test::Unit::TestCase with_env('REQUEST_METHOD'=>'GET') { assert_nil(URI("http://192.0.2.1/").find_proxy) } + with_env('CGI_HTTP_PROXY'=>'http://127.0.0.1:8080', 'REQUEST_METHOD'=>'GET') { + assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy) + } with_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'192.0.2.2') { assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy) assert_nil(URI("http://192.0.2.2/").find_proxy) -- cgit v1.2.3