diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-30 00:46:05 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-30 00:46:05 +0000 |
commit | e79d163caf09dbeeb5197576b8e364448f3bbac0 (patch) | |
tree | f267b25769bb93fee20856aefe508d4cc0655b62 /test/open-uri | |
parent | 1d7cfff09b59c1ca226777f7e50c90050249214e (diff) |
* 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
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/open-uri')
-rw-r--r-- | test/open-uri/test_open-uri.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb index c64c2be324..49b3e3da06 100644 --- a/test/open-uri/test_open-uri.rb +++ b/test/open-uri/test_open-uri.rb @@ -372,6 +372,42 @@ class TestOpenURI < Test::Unit::TestCase } 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" } |