diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-14 03:30:02 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-14 03:30:02 +0000 |
commit | 4de117a61517e839f2c45eaf45d56fc243d6d5b2 (patch) | |
tree | 7cb5af7a7eb513e5dddf5e343746b1611e628387 /test/rubygems/test_gem_request.rb | |
parent | e548c09d429a5136285ea81aed418685359ed124 (diff) | |
download | ruby-4de117a61517e839f2c45eaf45d56fc243d6d5b2.tar.gz |
* lib/rubygems: Update to RubyGems 2.4.1 master(713ab65)
Complete history at:
https://github.com/rubygems/rubygems/blob/master/History.txt#L3-L216
* test/rubygems: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_request.rb')
-rw-r--r-- | test/rubygems/test_gem_request.rb | 136 |
1 files changed, 75 insertions, 61 deletions
diff --git a/test/rubygems/test_gem_request.rb b/test/rubygems/test_gem_request.rb index bcbbcf1f99..c45d5d86fd 100644 --- a/test/rubygems/test_gem_request.rb +++ b/test/rubygems/test_gem_request.rb @@ -11,6 +11,10 @@ class TestGemRequest < Gem::TestCase PUBLIC_CERT_FILE = cert_path 'public' SSL_CERT = load_cert 'ssl' + def make_request uri, request_class, last_modified, proxy + Gem::Request.create_with_proxy uri, request_class, last_modified, proxy + end + def setup @proxies = %w[http_proxy HTTP_PROXY http_proxy_user HTTP_PROXY_USER http_proxy_pass HTTP_PROXY_PASS no_proxy NO_PROXY] @old_proxies = @proxies.map {|k| ENV[k] } @@ -21,7 +25,7 @@ class TestGemRequest < Gem::TestCase @proxy_uri = "http://localhost:1234" @uri = URI('http://example') - @request = Gem::Request.new @uri, nil, nil, nil + @request = make_request @uri, nil, nil, nil end def teardown @@ -33,7 +37,7 @@ class TestGemRequest < Gem::TestCase def test_initialize_proxy proxy_uri = 'http://proxy.example.com' - request = Gem::Request.new @uri, nil, nil, proxy_uri + request = make_request @uri, nil, nil, proxy_uri assert_equal proxy_uri, request.proxy_uri.to_s end @@ -41,7 +45,7 @@ class TestGemRequest < Gem::TestCase def test_initialize_proxy_URI proxy_uri = 'http://proxy.example.com' - request = Gem::Request.new @uri, nil, nil, URI(proxy_uri) + request = make_request @uri, nil, nil, URI(proxy_uri) assert_equal proxy_uri, request.proxy_uri.to_s end @@ -51,7 +55,7 @@ class TestGemRequest < Gem::TestCase ENV['http_proxy_user'] = 'foo' ENV['http_proxy_pass'] = 'bar' - request = Gem::Request.new @uri, nil, nil, nil + request = make_request @uri, nil, nil, nil proxy = request.proxy_uri @@ -62,7 +66,7 @@ class TestGemRequest < Gem::TestCase def test_initialize_proxy_ENV_https ENV['https_proxy'] = @proxy_uri - request = Gem::Request.new URI('https://example'), nil, nil, nil + request = make_request URI('https://example'), nil, nil, nil proxy = request.proxy_uri @@ -72,13 +76,13 @@ class TestGemRequest < Gem::TestCase def test_configure_connection_for_https connection = Net::HTTP.new 'localhost', 443 - request = Gem::Request.new URI('https://example'), nil, nil, nil - - def request.add_rubygems_trusted_certs store - store.add_cert TestGemRequest::PUBLIC_CERT - end + request = Class.new(Gem::Request) { + def self.get_cert_files + [TestGemRequest::PUBLIC_CERT_FILE] + end + }.create_with_proxy URI('https://example'), nil, nil, nil - request.configure_connection_for_https connection + Gem::Request.configure_connection_for_https connection, request.cert_files cert_store = connection.cert_store @@ -91,13 +95,13 @@ class TestGemRequest < Gem::TestCase connection = Net::HTTP.new 'localhost', 443 - request = Gem::Request.new URI('https://example'), nil, nil, nil + request = Class.new(Gem::Request) { + def self.get_cert_files + [TestGemRequest::PUBLIC_CERT_FILE] + end + }.create_with_proxy URI('https://example'), nil, nil, nil - def request.add_rubygems_trusted_certs store - store.add_cert TestGemRequest::PUBLIC_CERT - end - - request.configure_connection_for_https connection + Gem::Request.configure_connection_for_https connection, request.cert_files cert_store = connection.cert_store @@ -109,16 +113,18 @@ class TestGemRequest < Gem::TestCase def test_get_proxy_from_env_fallback ENV['http_proxy'] = @proxy_uri - - proxy = @request.get_proxy_from_env 'https' + request = make_request @uri, nil, nil, nil + proxy = request.proxy_uri assert_equal URI(@proxy_uri), proxy end def test_get_proxy_from_env_https ENV['https_proxy'] = @proxy_uri + uri = URI('https://example') + request = make_request uri, nil, nil, nil - proxy = @request.get_proxy_from_env 'https' + proxy = request.proxy_uri assert_equal URI(@proxy_uri), proxy end @@ -127,8 +133,9 @@ class TestGemRequest < Gem::TestCase ENV['http_proxy'] = @proxy_uri ENV['http_proxy_user'] = 'foo\user' ENV['http_proxy_pass'] = 'my bar' + request = make_request @uri, nil, nil, nil - proxy = @request.get_proxy_from_env + proxy = request.proxy_uri assert_equal 'foo\user', Gem::UriFormatter.new(proxy.user).unescape assert_equal 'my bar', Gem::UriFormatter.new(proxy.password).unescape @@ -138,8 +145,9 @@ class TestGemRequest < Gem::TestCase ENV['http_proxy'] = @proxy_uri ENV['http_proxy_user'] = 'foo@user' ENV['http_proxy_pass'] = 'my@bar' + request = make_request @uri, nil, nil, nil - proxy = @request.get_proxy_from_env + proxy = request.proxy_uri assert_equal 'foo%40user', proxy.user assert_equal 'my%40bar', proxy.password @@ -147,23 +155,26 @@ class TestGemRequest < Gem::TestCase def test_get_proxy_from_env_normalize ENV['HTTP_PROXY'] = 'fakeurl:12345' + request = make_request @uri, nil, nil, nil - assert_equal 'http://fakeurl:12345', @request.get_proxy_from_env.to_s + assert_equal 'http://fakeurl:12345', request.proxy_uri.to_s end def test_get_proxy_from_env_empty ENV['HTTP_PROXY'] = '' ENV.delete 'http_proxy' + request = make_request @uri, nil, nil, nil - assert_nil @request.get_proxy_from_env + assert_nil request.proxy_uri end def test_fetch uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}" - @request = Gem::Request.new(uri, Net::HTTP::Get, nil, nil) - util_stub_connection_for :body => :junk, :code => 200 + response = util_stub_net_http(:body => :junk, :code => 200) do + @request = make_request(uri, Net::HTTP::Get, nil, nil) - response = @request.fetch + @request.fetch + end assert_equal 200, response.code assert_equal :junk, response.body @@ -171,34 +182,34 @@ class TestGemRequest < Gem::TestCase def test_fetch_basic_auth uri = URI.parse "https://user:pass@example.rubygems/specs.#{Gem.marshal_version}" - @request = Gem::Request.new(uri, Net::HTTP::Get, nil, nil) - conn = util_stub_connection_for :body => :junk, :code => 200 - - @request.fetch + conn = util_stub_net_http(:body => :junk, :code => 200) do |c| + @request = make_request(uri, Net::HTTP::Get, nil, nil) + @request.fetch + c + end auth_header = conn.payload['Authorization'] - assert_equal "Basic #{Base64.encode64('user:pass')}".strip, auth_header end def test_fetch_basic_auth_encoded uri = URI.parse "https://user:%7BDEScede%7Dpass@example.rubygems/specs.#{Gem.marshal_version}" - @request = Gem::Request.new(uri, Net::HTTP::Get, nil, nil) - conn = util_stub_connection_for :body => :junk, :code => 200 - - @request.fetch + conn = util_stub_net_http(:body => :junk, :code => 200) do |c| + @request = make_request(uri, Net::HTTP::Get, nil, nil) + @request.fetch + c + end auth_header = conn.payload['Authorization'] - assert_equal "Basic #{Base64.encode64('user:{DEScede}pass')}".strip, auth_header end def test_fetch_head uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}" - @request = Gem::Request.new(uri, Net::HTTP::Get, nil, nil) - util_stub_connection_for :body => '', :code => 200 - - response = @request.fetch + response = util_stub_net_http(:body => '', :code => 200) do |conn| + @request = make_request(uri, Net::HTTP::Get, nil, nil) + @request.fetch + end assert_equal 200, response.code assert_equal '', response.body @@ -207,10 +218,10 @@ class TestGemRequest < Gem::TestCase def test_fetch_unmodified uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}" t = Time.utc(2013, 1, 2, 3, 4, 5) - @request = Gem::Request.new(uri, Net::HTTP::Get, t, nil) - conn = util_stub_connection_for :body => '', :code => 304 - - response = @request.fetch + conn, response = util_stub_net_http(:body => '', :code => 304) do |c| + @request = make_request(uri, Net::HTTP::Get, t, nil) + [c, @request.fetch] + end assert_equal 304, response.code assert_equal '', response.body @@ -221,7 +232,7 @@ class TestGemRequest < Gem::TestCase end def test_user_agent - ua = Gem::Request.new(@uri, nil, nil, nil).user_agent + ua = make_request(@uri, nil, nil, nil).user_agent assert_match %r%^RubyGems/\S+ \S+ Ruby/\S+ \(.*?\)%, ua assert_match %r%RubyGems/#{Regexp.escape Gem::VERSION}%, ua @@ -236,7 +247,7 @@ class TestGemRequest < Gem::TestCase Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE) Object.send :const_set, :RUBY_ENGINE, 'vroom' - ua = Gem::Request.new(@uri, nil, nil, nil).user_agent + ua = make_request(@uri, nil, nil, nil).user_agent assert_match %r%\) vroom%, ua ensure @@ -249,7 +260,7 @@ class TestGemRequest < Gem::TestCase Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE) Object.send :const_set, :RUBY_ENGINE, 'ruby' - ua = Gem::Request.new(@uri, nil, nil, nil).user_agent + ua = make_request(@uri, nil, nil, nil).user_agent assert_match %r%\)%, ua ensure @@ -262,7 +273,7 @@ class TestGemRequest < Gem::TestCase Object.send :remove_const, :RUBY_PATCHLEVEL Object.send :const_set, :RUBY_PATCHLEVEL, 5 - ua = Gem::Request.new(@uri, nil, nil, nil).user_agent + ua = make_request(@uri, nil, nil, nil).user_agent assert_match %r% patchlevel 5\)%, ua ensure @@ -277,7 +288,7 @@ class TestGemRequest < Gem::TestCase Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) Object.send :const_set, :RUBY_REVISION, 6 - ua = Gem::Request.new(@uri, nil, nil, nil).user_agent + ua = make_request(@uri, nil, nil, nil).user_agent assert_match %r% revision 6\)%, ua assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}dev%, ua @@ -292,7 +303,7 @@ class TestGemRequest < Gem::TestCase Object.send :const_set, :RUBY_PATCHLEVEL, -1 Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) - ua = Gem::Request.new(@uri, nil, nil, nil).user_agent + ua = make_request(@uri, nil, nil, nil).user_agent assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE}\)%, ua ensure @@ -318,21 +329,24 @@ class TestGemRequest < Gem::TestCase @orig_RUBY_REVISION = RUBY_REVISION if defined? RUBY_REVISION end - def util_stub_connection_for hash - def @request.connection= conn - @conn = conn - end - - def @request.connection_for uri - @conn - end - - @request.connection = Conn.new OpenStruct.new(hash) + def util_stub_net_http hash + old_client = Gem::Request::ConnectionPools.client + conn = Conn.new OpenStruct.new(hash) + Gem::Request::ConnectionPools.client = conn + yield conn + ensure + Gem::Request::ConnectionPools.client = old_client end class Conn attr_accessor :payload + def new *args; self; end + def use_ssl=(bool); end + def verify_mode=(setting); end + def cert_store=(setting); end + def start; end + def initialize(response) @response = response self.payload = nil |