Project

General

Profile

Bug #8979 » rubygems-remote_fetcher.patch

tommy (Masahiro Tomita), 10/03/2013 12:56 AM

View differences:

lib/rubygems/remote_fetcher.rb
response['content-length'].to_i
end
def escape_auth_info(str)
str && URI.encode_www_form_component(str)
end
def unescape_auth_info(str)
str && URI.decode_www_form_component(str)
end
def escape(str)
return unless str
@uri_parser ||= uri_escaper
......
if uri and uri.user.nil? and uri.password.nil? then
# Probably we have http_proxy_* variables?
uri.user = escape(ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER'])
uri.password = escape(ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS'])
uri.user = escape_auth_info(ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER'])
uri.password = escape_auth_info(ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS'])
end
uri
......
net_http_args += [
@proxy_uri.host,
@proxy_uri.port,
@proxy_uri.user,
@proxy_uri.password
unescape_auth_info(@proxy_uri.user),
unescape_auth_info(@proxy_uri.password)
]
end
test/rubygems/test_gem_remote_fetcher.rb
uri.user, uri.password = 'domain%5Cuser', 'bar'
fetcher = Gem::RemoteFetcher.new uri.to_s
proxy = fetcher.instance_variable_get("@proxy_uri")
assert_equal 'domain\user', fetcher.unescape(proxy.user)
assert_equal 'domain\user', fetcher.unescape_auth_info(proxy.user)
assert_equal 'bar', proxy.password
assert_data_from_proxy fetcher.fetch_path(@server_uri)
end
......
fetcher = Gem::RemoteFetcher.new uri.to_s
proxy = fetcher.instance_variable_get("@proxy_uri")
assert_equal 'user', proxy.user
assert_equal 'my pass', fetcher.unescape(proxy.password)
assert_equal 'my pass', fetcher.unescape_auth_info(proxy.password)
assert_data_from_proxy fetcher.fetch_path(@server_uri)
end
end
......
ENV['http_proxy_pass'] = 'my bar'
fetcher = Gem::RemoteFetcher.new nil
proxy = fetcher.instance_variable_get("@proxy_uri")
assert_equal 'foo\user', fetcher.unescape(proxy.user)
assert_equal 'my bar', fetcher.unescape(proxy.password)
assert_equal 'foo\user', fetcher.unescape_auth_info(proxy.user)
assert_equal 'my bar', fetcher.unescape_auth_info(proxy.password)
assert_data_from_proxy fetcher.fetch_path(@server_uri)
end
use_ui @ui do
ENV['http_proxy'] = @proxy_uri
ENV['http_proxy_user'] = 'foo@user'
ENV['http_proxy_pass'] = 'my@bar'
fetcher = Gem::RemoteFetcher.new nil
proxy = fetcher.instance_variable_get("@proxy_uri")
assert_equal 'foo@user', fetcher.unescape_auth_info(proxy.user)
assert_equal 'my@bar', fetcher.unescape_auth_info(proxy.password)
assert_data_from_proxy fetcher.fetch_path(@server_uri)
end
end
    (1-1/1)