[#43181] [Ruby 1.9-Bug#4387][Open] test_socket_connect_nonblock(TestSocketAddrinfo) がまれに失敗する — Motohiro KOSAKI <redmine@...>
Bug #4387: test_socket_connect_nonblock(TestSocketAddrinfo) がまれに失敗する
6 messages
2011/02/09
[#43186] [Ruby 1.9-Bug#4388][Open] open-uriで環境変数http_proxyを使うときに認証付きのProxyが使えません — あつし よしだ <redmine@...>
Bug #4388: open-uri=E3=81=A7=E7=92=B0=E5=A2=83=E5=A4=89=E6=95=B0http_prox=
11 messages
2011/02/10
[#43192] [Ruby 1.9-Bug#4388] open-uriで環境変数http_proxyを使うときに認証付きのProxyが使えません
— あつし よしだ <redmine@...>
2011/02/11
チケット #4388 が更新されました。 (by あつし よしだ)
[#43193] Re: [Ruby 1.9-Bug#4388] open-uriで環境変数http_proxyを使うときに認証付きのProxyが使えません
— Tanaka Akira <akr@...>
2011/02/11
2011年2月11日12:59 あつし よしだ <redmine@ruby-lang.org>:
[#43195] Re: [Ruby 1.9-Bug#4388] open-uriで環境変数http_proxyを使うときに認証付きのProxyが使えません
— Mitsuru Ogino <ogino@...>
2011/02/11
荻野と言います。
[#43197] Re: [Ruby 1.9-Bug#4388] open-uriで環境変数http_proxyを使うときに認証付きのProxyが使えません
— Yukihiro Matsumoto <matz@...>
2011/02/11
まつもと ゆきひろです
[#43199] Re: [ruby-changes:18827] Ruby:r30852 (trunk): * thread.c (rb_thread_io_blocking_region): new function to run — SASADA Koichi <ko1@...>
ささだです.
4 messages
2011/02/12
[#43203] [Ruby 1.9-Bug#4397][Open] test-mkmf fails due to compilation errors — Shyouhei Urabe <redmine@...>
Bug #4397: test-mkmf fails due to compilation errors
10 messages
2011/02/14
[#43204] Re: [Ruby 1.9-Bug#4397][Open] test-mkmf fails due to compilation errors
— KOSAKI Motohiro <kosaki.motohiro@...>
2011/02/14
2011年2月14日18:12 Shyouhei Urabe <redmine@ruby-lang.org>:
[#43205] Re: [Ruby 1.9-Bug#4397][Open] test-mkmf fails due to compilation errors
— Urabe Shyouhei <shyouhei@...>
2011/02/14
(2011/02/14 18:24), KOSAKI Motohiro wrote:
[#43206] Re: [Ruby 1.9-Bug#4397][Open] test-mkmf fails due to compilation errors
— KOSAKI Motohiro <kosaki.motohiro@...>
2011/02/14
> これでもまだ長いと思われるので更に解説すると、debugflagsによりgccはstrict ansi
[#43222] Rubyのtest-allを並列化するパッチを書きました — "Shota Fukumori (sora_h)" <sorah@...>
sora_hです。おはようございます。
8 messages
2011/02/17
[#43226] [Ruby 1.9-Feature#4415][Open] Rubyのtest-allを並列化するパッチが完成しました — Shota Fukumori <redmine@...>
Feature #4415: Rubyのtest-allを並列化するパッチが完成しました
6 messages
2011/02/21
[#43241] [ANN] redmine.ruby-lang.orgメンテナンスのお知らせ — "Yuki Sonoda (Yugui)" <yugui@...>
-----BEGIN PGP SIGNED MESSAGE-----
7 messages
2011/02/22
[#43263] Re: [ruby-list:47910] [ANN] redmine.ruby-lang.orgメンテナンスのお知らせ
— "Yuki Sonoda (Yugui)" <yugui@...>
2011/02/23
-----BEGIN PGP SIGNED MESSAGE-----
[#43265] Re: [ruby-list:47910] [ANN] redmine.ruby-lang.orgメンテナンスのお知らせ
— Fujioka <fuj@...>
2011/02/24
xibbarこと藤岡です。
[#43253] [Ruby 1.9 - Bug #4430] (Open) 新型redmine.ruby-lang.orgのテスト — Yuki Sonoda <yugui@...>
5 messages
2011/02/23
[#43272] [Ruby 1.9 - Bug #4443] [Open] odd evaluation order in a multiple assignment — Yusuke Endoh <mame@...>
13 messages
2011/02/24
[#43276] iseq_compile_each()でのマジックナンバ — きたざわけんいち <peisunstar@...>
きたざわです。
15 messages
2011/02/27
[#43303] Re: iseq_compile_each()でのマジックナンバ
— nagachika <nagachika00@...>
2011/03/04
近永と申します。
[#43304] Re: iseq_compile_each()でのマジックナンバ
— Yusuke ENDOH <mame@...>
2011/03/04
遠藤です。
[ruby-dev:43196] Re: [Ruby 1.9-Bug#4388] open-uriで環境変数http_proxyを使うときに認証付きのProxyが使えません
From:
"Shota Fukumori (sora_h)" <sorah@...>
Date:
2011-02-11 11:40:39 UTC
List:
ruby-dev #43196
#ruby-ja @ircnetでも出ていましたが、warningを出力しながらも使用するというのはどうでしょうか。 patchも書きました 2011/2/11 Tanaka Akira <akr@fsij.org>: > とくにおかしいとは思いません。 > http_proxy は URI ですが、query や fragment など他にも無視するところは > たくさんあります。 -- Shota Fukumori a.k.a. @sora_h - http://codnote.net/
Attachments (1)
open-uri_with_http_proxy2.patch
(3.12 KB, text/x-diff)
diff --git a/lib/open-uri.rb b/lib/open-uri.rb
index c8393fa..807283a 100644
--- a/lib/open-uri.rb
+++ b/lib/open-uri.rb
@@ -183,7 +183,15 @@ module OpenURI
end
case opt_proxy
when true
- find_proxy = lambda {|u| pxy = u.find_proxy; pxy ? [pxy, nil, nil] : nil}
+ find_proxy = lambda {|u|
+ if pxy = u.find_proxy
+ (proxy_user, proxy_pass) = pxy.userinfo.to_s.split(":")
+ warn "#{caller(1)[0}}: warning: Including password or username has security problem." if proxy_user || proxy_pass
+ [pxy, proxy_user, proxy_pass]
+ else
+ nil
+ end
+ }
when nil, false
find_proxy = lambda {|u| nil}
when String
@@ -736,17 +744,17 @@ module URI
proxy_uri = ENV[name] || ENV[name.upcase]
end
- if proxy_uri && self.hostname
- require 'socket'
- begin
- addr = IPSocket.getaddress(self.hostname)
- proxy_uri = nil if /\A127\.|\A::1\z/ =~ addr
- rescue SocketError
- end
- end
-
if proxy_uri
proxy_uri = URI.parse(proxy_uri)
+ if self.hostname
+ require 'socket'
+ begin
+ addr = IPSocket.getaddress(self.hostname)
+ return nil if /\A127\.|\A::1\z/ =~ addr && proxy_uri.userinfo.nil?
+ rescue SocketError
+ end
+ end
+
name = 'no_proxy'
if no_proxy = ENV[name] || ENV[name.upcase]
no_proxy.scan(/([^:,]*)(?::(\d+))?/) {|host, port|
diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb
index 14f08ff..621649e 100644
--- a/test/open-uri/test_open-uri.rb
+++ b/test/open-uri/test_open-uri.rb
@@ -271,6 +271,42 @@ class TestOpenURI < Test::Unit::TestCase
}
end
+ def test_proxy_http_basic_authentication_from_env
+ with_http {|srv, dr, url|
+ log = ''
+ proxy_user = 'user'
+ proxy_pass = 'pass'
+ proxy = WEBrick::HTTPProxyServer.new({
+ :ServerType => Thread,
+ :Logger => WEBrick::Log.new(NullLog),
+ :AccessLog => [[NullLog, ""]],
+ :ProxyAuthProc => lambda {|req, res|
+ log << req.request_line
+ auth = ["#{proxy_user}:#{proxy_pass}"].pack('m').chomp
+ if req["Proxy-Authorization"] != "Basic #{auth}"
+ raise WEBrick::HTTPStatus::ProxyAuthenticationRequired
+ end
+ },
+ :BindAddress => '127.0.0.1',
+ :Port => 0})
+ _, proxy_port, _, proxy_host = proxy.listeners[0].addr
+ proxy_url = "http://#{proxy_user}:#{proxy_pass}@#{proxy_host}:#{proxy_port}"
+ ::ENV['http_proxy'] = proxy_url
+ begin
+ th = proxy.start
+ open("#{dr}/proxy", "w") {|f| f << "proxy" }
+ open("#{url}/proxy") {|f|
+ assert_equal("200", f.status[0])
+ assert_equal("proxy", f.read)
+ }
+ assert_match(/#{Regexp.quote url}/, log); log.clear
+ assert_equal("", log); log.clear
+ ensure
+ proxy.shutdown
+ end
+ }
+ 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" }