ruby-changes:42358
From: hsbt <ko1@a...>
Date: Wed, 30 Mar 2016 09:46:13 +0900 (JST)
Subject: [ruby-changes:42358] hsbt:r54432 (trunk): * lib/open-uri.rb: Use `userinfo` for authenticated proxy.
hsbt 2016-03-30 09:46:05 +0900 (Wed, 30 Mar 2016) New Revision: 54432 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54432 Log: * lib/open-uri.rb: Use `userinfo` for authenticated proxy. [fix GH-1148] Patch by @SokichiFujita * test/open-uri/test_open-uri.rb: ditto. [fix GH-1309] Patch by @jdamick Modified files: trunk/ChangeLog trunk/lib/open-uri.rb trunk/test/open-uri/test_open-uri.rb Index: lib/open-uri.rb =================================================================== --- lib/open-uri.rb (revision 54431) +++ lib/open-uri.rb (revision 54432) @@ -270,6 +270,9 @@ module OpenURI https://github.com/ruby/ruby/blob/trunk/lib/open-uri.rb#L270 if URI::HTTP === target # HTTP or HTTPS if proxy + unless proxy_user && proxy_pass + proxy_user, proxy_pass = proxy_uri.userinfo.split(':') if proxy_uri.userinfo + end if proxy_user && proxy_pass klass = Net::HTTP::Proxy(proxy_uri.hostname, proxy_uri.port, proxy_user, proxy_pass) else Index: test/open-uri/test_open-uri.rb =================================================================== --- test/open-uri/test_open-uri.rb (revision 54431) +++ test/open-uri/test_open-uri.rb (revision 54432) @@ -372,6 +372,42 @@ class TestOpenURI < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_open-uri.rb#L372 } end + def test_authenticated_proxy_http_basic_authentication_success + with_http {|srv, dr, url| + proxy_log = StringIO.new(''.dup) + proxy_logger = WEBrick::Log.new(proxy_log, WEBrick::BasicLog::WARN) + proxy_auth_log = ''.dup + proxy = WEBrick::HTTPProxyServer.new({ + :ServerType => Thread, + :Logger => proxy_logger, + :AccessLog => [[NullLog, ""]], + :ProxyAuthProc => lambda {|req, res| + proxy_auth_log << req.request_line + if req["Proxy-Authorization"] != "Basic #{['user:pass'].pack('m').chomp}" + raise WEBrick::HTTPStatus::ProxyAuthenticationRequired + end + }, + :BindAddress => '127.0.0.1', + :Port => 0}) + _, proxy_port, _, proxy_host = proxy.listeners[0].addr + proxy_url = "http://user:pass@#{proxy_host}:#{proxy_port}/" + begin + th = proxy.start + srv.mount_proc("/proxy", lambda { |req, res| res.body = "proxy" } ) + open("#{url}/proxy", :proxy => proxy_url) {|f| + assert_equal("200", f.status[0]) + assert_equal("proxy", f.read) + } + assert_match(/#{Regexp.quote url}/, proxy_auth_log); proxy_auth_log.clear + assert_equal("", proxy_auth_log); proxy_auth_log.clear + ensure + proxy.shutdown + th.join + end + assert_equal("", proxy_log.string) + } + end + def test_redirect with_http {|srv, dr, url| srv.mount_proc("/r1/") {|req, res| res.status = 301; res["location"] = "#{url}/r2"; res.body = "r1" } Index: ChangeLog =================================================================== --- ChangeLog (revision 54431) +++ ChangeLog (revision 54432) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Mar 30 09:46:01 2016 SHIBATA Hiroshi <hsbt@r...> + + * lib/open-uri.rb: Use `userinfo` for authenticated proxy. + [fix GH-1148] Patch by @SokichiFujita + * test/open-uri/test_open-uri.rb: ditto. + [fix GH-1309] Patch by @jdamick + Wed Mar 30 01:56:06 2016 NARUSE, Yui <naruse@r...> * ext/nkf/nkf-utf8/nkf.c: Merge upstream 4f3edf80a0. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/