diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2023-01-29 21:28:29 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-12-13 12:16:55 +0900 |
commit | 90317472e87692fff1c864d129d60130dc3bab2c (patch) | |
tree | 698f2aa5911cc1a4512c9019b6e785495c47d3bc /spec/bundler | |
parent | ce924ce1fb029f19fd34a43f2012a485f4f62b53 (diff) |
[rubygems/rubygems] Use vendored net-http in Bundler
https://github.com/rubygems/rubygems/commit/0d758e8926
Diffstat (limited to 'spec/bundler')
-rw-r--r-- | spec/bundler/bundler/compact_index_client/updater_spec.rb | 26 | ||||
-rw-r--r-- | spec/bundler/bundler/fetcher/downloader_spec.rb | 38 | ||||
-rw-r--r-- | spec/bundler/bundler/fetcher_spec.rb | 2 | ||||
-rw-r--r-- | spec/bundler/install/gems/compact_index_spec.rb | 4 | ||||
-rw-r--r-- | spec/bundler/install/gems/dependency_api_spec.rb | 4 | ||||
-rw-r--r-- | spec/bundler/support/artifice/fail.rb | 10 | ||||
-rw-r--r-- | spec/bundler/support/artifice/helpers/artifice.rb | 6 | ||||
-rw-r--r-- | spec/bundler/support/artifice/helpers/rack_request.rb | 22 | ||||
-rw-r--r-- | spec/bundler/support/artifice/vcr.rb | 10 |
9 files changed, 61 insertions, 61 deletions
diff --git a/spec/bundler/bundler/compact_index_client/updater_spec.rb b/spec/bundler/bundler/compact_index_client/updater_spec.rb index 1f11dffac9..51b838d2d2 100644 --- a/spec/bundler/bundler/compact_index_client/updater_spec.rb +++ b/spec/bundler/bundler/compact_index_client/updater_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "net/http" +require "bundler/vendored_net_http" require "bundler/compact_index_client" require "bundler/compact_index_client/updater" require "tmpdir" @@ -64,8 +64,8 @@ RSpec.describe Bundler::CompactIndexClient::Updater do it "does nothing if etags match" do expect(fetcher).to receive(:call).once.with(remote_path, headers).and_return(response) - allow(response).to receive(:is_a?).with(Net::HTTPPartialContent) { false } - allow(response).to receive(:is_a?).with(Net::HTTPNotModified) { true } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPPartialContent) { false } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPNotModified) { true } updater.update(remote_path, local_path, etag_path) @@ -77,8 +77,8 @@ RSpec.describe Bundler::CompactIndexClient::Updater do expect(fetcher).to receive(:call).once.with(remote_path, headers).and_return(response) allow(response).to receive(:[]).with("Repr-Digest") { "sha-256=:#{digest}:" } allow(response).to receive(:[]).with("ETag") { "NewEtag" } - allow(response).to receive(:is_a?).with(Net::HTTPPartialContent) { true } - allow(response).to receive(:is_a?).with(Net::HTTPNotModified) { false } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPPartialContent) { true } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPNotModified) { false } allow(response).to receive(:body) { "c123" } updater.update(remote_path, local_path, etag_path) @@ -102,7 +102,7 @@ RSpec.describe Bundler::CompactIndexClient::Updater do it "tries the request again if the partial response fails digest check" do allow(response).to receive(:[]).with("Repr-Digest") { "sha-256=:baddigest:" } allow(response).to receive(:body) { "the beginning of the file changed" } - allow(response).to receive(:is_a?).with(Net::HTTPPartialContent) { true } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPPartialContent) { true } expect(fetcher).to receive(:call).once.with(remote_path, headers).and_return(response) full_response = double(:full_response, body: full_body, is_a?: false) @@ -129,8 +129,8 @@ RSpec.describe Bundler::CompactIndexClient::Updater do it "saves only the etag_path if generated etag matches" do expect(fetcher).to receive(:call).once.with(remote_path, headers).and_return(response) - allow(response).to receive(:is_a?).with(Net::HTTPPartialContent) { false } - allow(response).to receive(:is_a?).with(Net::HTTPNotModified) { true } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPPartialContent) { false } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPNotModified) { true } updater.update(remote_path, local_path, etag_path) @@ -142,8 +142,8 @@ RSpec.describe Bundler::CompactIndexClient::Updater do expect(fetcher).to receive(:call).once.with(remote_path, headers).and_return(response) allow(response).to receive(:[]).with("Repr-Digest") { "sha-256=:#{digest}:" } allow(response).to receive(:[]).with("ETag") { "OpaqueEtag" } - allow(response).to receive(:is_a?).with(Net::HTTPPartialContent) { true } - allow(response).to receive(:is_a?).with(Net::HTTPNotModified) { false } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPPartialContent) { true } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPNotModified) { false } allow(response).to receive(:body) { "c123" } updater.update(remote_path, local_path, etag_path) @@ -157,8 +157,8 @@ RSpec.describe Bundler::CompactIndexClient::Updater do allow(response).to receive(:[]).with("Repr-Digest") { nil } allow(response).to receive(:[]).with("Digest") { nil } allow(response).to receive(:[]).with("ETag") { "OpaqueEtag" } - allow(response).to receive(:is_a?).with(Net::HTTPPartialContent) { false } - allow(response).to receive(:is_a?).with(Net::HTTPNotModified) { false } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPPartialContent) { false } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPNotModified) { false } allow(response).to receive(:body) { full_body } updater.update(remote_path, local_path, etag_path) @@ -170,7 +170,7 @@ RSpec.describe Bundler::CompactIndexClient::Updater do it "tries the request again if the partial response fails digest check" do allow(response).to receive(:[]).with("Repr-Digest") { "sha-256=:baddigest:" } allow(response).to receive(:body) { "the beginning of the file changed" } - allow(response).to receive(:is_a?).with(Net::HTTPPartialContent) { true } + allow(response).to receive(:is_a?).with(Gem::Net::HTTPPartialContent) { true } expect(fetcher).to receive(:call).once.with(remote_path, headers) do # During the failed first request, we simulate another process writing the etag. # This ensures the second request doesn't generate the md5 etag again but just uses whatever is written. diff --git a/spec/bundler/bundler/fetcher/downloader_spec.rb b/spec/bundler/bundler/fetcher/downloader_spec.rb index 22aa3a8b0c..88a8c174f1 100644 --- a/spec/bundler/bundler/fetcher/downloader_spec.rb +++ b/spec/bundler/bundler/fetcher/downloader_spec.rb @@ -27,7 +27,7 @@ RSpec.describe Bundler::Fetcher::Downloader do end context "logging" do - let(:http_response) { Net::HTTPSuccess.new("1.1", 200, "Success") } + let(:http_response) { Gem::Net::HTTPSuccess.new("1.1", 200, "Success") } it "should log the HTTP response code and message to debug" do expect(Bundler).to receive_message_chain(:ui, :debug).with("HTTP 200 Success #{uri}") @@ -35,8 +35,8 @@ RSpec.describe Bundler::Fetcher::Downloader do end end - context "when the request response is a Net::HTTPRedirection" do - let(:http_response) { Net::HTTPRedirection.new(httpv, 308, "Moved") } + context "when the request response is a Gem::Net::HTTPRedirection" do + let(:http_response) { Gem::Net::HTTPRedirection.new(httpv, 308, "Moved") } before { http_response["location"] = "http://www.redirect-uri.com/api/v2/endpoint" } @@ -59,24 +59,24 @@ RSpec.describe Bundler::Fetcher::Downloader do end end - context "when the request response is a Net::HTTPSuccess" do - let(:http_response) { Net::HTTPSuccess.new("1.1", 200, "Success") } + context "when the request response is a Gem::Net::HTTPSuccess" do + let(:http_response) { Gem::Net::HTTPSuccess.new("1.1", 200, "Success") } it "should return the response body" do expect(subject.fetch(uri, options, counter)).to eq(http_response) end end - context "when the request response is a Net::HTTPRequestEntityTooLarge" do - let(:http_response) { Net::HTTPRequestEntityTooLarge.new("1.1", 413, "Too Big") } + context "when the request response is a Gem::Net::HTTPRequestEntityTooLarge" do + let(:http_response) { Gem::Net::HTTPRequestEntityTooLarge.new("1.1", 413, "Too Big") } it "should raise a Bundler::Fetcher::FallbackError with the response body" do expect { subject.fetch(uri, options, counter) }.to raise_error(Bundler::Fetcher::FallbackError, "Body with info") end end - context "when the request response is a Net::HTTPUnauthorized" do - let(:http_response) { Net::HTTPUnauthorized.new("1.1", 401, "Unauthorized") } + context "when the request response is a Gem::Net::HTTPUnauthorized" do + let(:http_response) { Gem::Net::HTTPUnauthorized.new("1.1", 401, "Unauthorized") } it "should raise a Bundler::Fetcher::AuthenticationRequiredError with the uri host" do expect { subject.fetch(uri, options, counter) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError, @@ -98,8 +98,8 @@ RSpec.describe Bundler::Fetcher::Downloader do end end - context "when the request response is a Net::HTTPForbidden" do - let(:http_response) { Net::HTTPForbidden.new("1.1", 403, "Forbidden") } + context "when the request response is a Gem::Net::HTTPForbidden" do + let(:http_response) { Gem::Net::HTTPForbidden.new("1.1", 403, "Forbidden") } let(:uri) { Bundler::URI("http://user:password@www.uri-to-fetch.com") } it "should raise a Bundler::Fetcher::AuthenticationForbiddenError with the uri host" do @@ -108,12 +108,12 @@ RSpec.describe Bundler::Fetcher::Downloader do end end - context "when the request response is a Net::HTTPNotFound" do - let(:http_response) { Net::HTTPNotFound.new("1.1", 404, "Not Found") } + context "when the request response is a Gem::Net::HTTPNotFound" do + let(:http_response) { Gem::Net::HTTPNotFound.new("1.1", 404, "Not Found") } - it "should raise a Bundler::Fetcher::FallbackError with Net::HTTPNotFound" do + it "should raise a Bundler::Fetcher::FallbackError with Gem::Net::HTTPNotFound" do expect { subject.fetch(uri, options, counter) }. - to raise_error(Bundler::Fetcher::FallbackError, "Net::HTTPNotFound: http://www.uri-to-fetch.com/api/v2/endpoint") + to raise_error(Bundler::Fetcher::FallbackError, "Gem::Net::HTTPNotFound: http://www.uri-to-fetch.com/api/v2/endpoint") end context "when the there are credentials provided in the request" do @@ -121,16 +121,16 @@ RSpec.describe Bundler::Fetcher::Downloader do it "should raise a Bundler::Fetcher::FallbackError that doesn't contain the password" do expect { subject.fetch(uri, options, counter) }. - to raise_error(Bundler::Fetcher::FallbackError, "Net::HTTPNotFound: http://username@www.uri-to-fetch.com/api/v2/endpoint") + to raise_error(Bundler::Fetcher::FallbackError, "Gem::Net::HTTPNotFound: http://username@www.uri-to-fetch.com/api/v2/endpoint") end end end context "when the request response is some other type" do - let(:http_response) { Net::HTTPBadGateway.new("1.1", 500, "Fatal Error") } + let(:http_response) { Gem::Net::HTTPBadGateway.new("1.1", 500, "Fatal Error") } it "should raise a Bundler::HTTPError with the response class and body" do - expect { subject.fetch(uri, options, counter) }.to raise_error(Bundler::HTTPError, "Net::HTTPBadGateway: Body with info") + expect { subject.fetch(uri, options, counter) }.to raise_error(Bundler::HTTPError, "Gem::Net::HTTPBadGateway: Body with info") end end end @@ -140,7 +140,7 @@ RSpec.describe Bundler::Fetcher::Downloader do let(:response) { double(:response) } before do - allow(Net::HTTP::Get).to receive(:new).with("/api/v2/endpoint", options).and_return(net_http_get) + allow(Gem::Net::HTTP::Get).to receive(:new).with("/api/v2/endpoint", options).and_return(net_http_get) allow(connection).to receive(:request).with(uri, net_http_get).and_return(response) end diff --git a/spec/bundler/bundler/fetcher_spec.rb b/spec/bundler/bundler/fetcher_spec.rb index 53d201d31d..5a2c568693 100644 --- a/spec/bundler/bundler/fetcher_spec.rb +++ b/spec/bundler/bundler/fetcher_spec.rb @@ -167,7 +167,7 @@ RSpec.describe Bundler::Fetcher do let(:version) { "1.3.17" } let(:platform) { "platform" } let(:downloader) { double("downloader") } - let(:body) { double(Net::HTTP::Get, body: downloaded_data) } + let(:body) { double(Gem::Net::HTTP::Get, body: downloaded_data) } context "when attempting to load a Gem::Specification" do let(:spec) { Gem::Specification.new(name, version) } diff --git a/spec/bundler/install/gems/compact_index_spec.rb b/spec/bundler/install/gems/compact_index_spec.rb index 5004553735..e3c891e4c1 100644 --- a/spec/bundler/install/gems/compact_index_spec.rb +++ b/spec/bundler/install/gems/compact_index_spec.rb @@ -206,7 +206,7 @@ RSpec.describe "compact index api" do expect(the_bundle).to include_gems "rack 1.0.0" end - it "handles host redirects without Net::HTTP::Persistent" do + it "handles host redirects without Gem::Net::HTTP::Persistent" do gemfile <<-G source "#{source_uri}" gem "rack" @@ -739,7 +739,7 @@ RSpec.describe "compact index api" do # Install a monkeypatch that reproduces the effects of openssl raising # a certificate validation error when RubyGems tries to connect. gemfile <<-G - class Net::HTTP + class Gem::Net::HTTP def start raise OpenSSL::SSL::SSLError, "certificate verify failed" end diff --git a/spec/bundler/install/gems/dependency_api_spec.rb b/spec/bundler/install/gems/dependency_api_spec.rb index 10a3ed4c70..e21164aec0 100644 --- a/spec/bundler/install/gems/dependency_api_spec.rb +++ b/spec/bundler/install/gems/dependency_api_spec.rb @@ -197,7 +197,7 @@ RSpec.describe "gemcutter's dependency API" do expect(the_bundle).to include_gems "rack 1.0.0" end - it "handles host redirects without Net::HTTP::Persistent" do + it "handles host redirects without Gem::Net::HTTP::Persistent" do gemfile <<-G source "#{source_uri}" gem "rack" @@ -723,7 +723,7 @@ RSpec.describe "gemcutter's dependency API" do # Install a monkeypatch that reproduces the effects of openssl raising # a certificate validation error when RubyGems tries to connect. gemfile <<-G - class Net::HTTP + class Gem::Net::HTTP def start raise OpenSSL::SSL::SSLError, "certificate verify failed" end diff --git a/spec/bundler/support/artifice/fail.rb b/spec/bundler/support/artifice/fail.rb index a6a8552893..8822e5b8e2 100644 --- a/spec/bundler/support/artifice/fail.rb +++ b/spec/bundler/support/artifice/fail.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require "net/http" +require "bundler/vendored_net_http" -class Fail < Net::HTTP - # Net::HTTP uses a @newimpl instance variable to decide whether +class Fail < Gem::Net::HTTP + # Gem::Net::HTTP uses a @newimpl instance variable to decide whether # to use a legacy implementation. Since we are subclassing - # Net::HTTP, we must set it + # Gem::Net::HTTP, we must set it @newimpl = true def request(req, body = nil, &block) @@ -23,5 +23,5 @@ end require_relative "helpers/artifice" -# Replace Net::HTTP with our failing subclass +# Replace Gem::Net::HTTP with our failing subclass Artifice.replace_net_http(::Fail) diff --git a/spec/bundler/support/artifice/helpers/artifice.rb b/spec/bundler/support/artifice/helpers/artifice.rb index b8c78614fb..788268295c 100644 --- a/spec/bundler/support/artifice/helpers/artifice.rb +++ b/spec/bundler/support/artifice/helpers/artifice.rb @@ -4,7 +4,7 @@ module Artifice # Activate Artifice with a particular Rack endpoint. # - # Calling this method will replace the Net::HTTP system + # Calling this method will replace the Gem::Net::HTTP system # with a replacement that routes all requests to the # Rack endpoint. # @@ -18,11 +18,11 @@ module Artifice # Deactivate the Artifice replacement. def self.deactivate - replace_net_http(::Net::HTTP) + replace_net_http(::Gem::Net::HTTP) end def self.replace_net_http(value) - ::Net.class_eval do + ::Gem::Net.class_eval do remove_const(:HTTP) const_set(:HTTP, value) end diff --git a/spec/bundler/support/artifice/helpers/rack_request.rb b/spec/bundler/support/artifice/helpers/rack_request.rb index 45023dfdd6..f419bacb8c 100644 --- a/spec/bundler/support/artifice/helpers/rack_request.rb +++ b/spec/bundler/support/artifice/helpers/rack_request.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "rack/test" -require "net/http" +require "bundler/vendored_net_http" module Artifice module Net @@ -16,25 +16,25 @@ module Artifice end end - class HTTP < ::Net::HTTP + class HTTP < ::Gem::Net::HTTP class << self attr_accessor :endpoint end - # Net::HTTP uses a @newimpl instance variable to decide whether + # Gem::Net::HTTP uses a @newimpl instance variable to decide whether # to use a legacy implementation. Since we are subclassing - # Net::HTTP, we must set it + # Gem::Net::HTTP, we must set it @newimpl = true # We don't need to connect, so blank out this method def connect end - # Replace the Net::HTTP request method with a method + # Replace the Gem::Net::HTTP request method with a method # that converts the request into a Rack request and # dispatches it to the Rack endpoint. # - # @param [Net::HTTPRequest] req A Net::HTTPRequest + # @param [Net::HTTPRequest] req A Gem::Net::HTTPRequest # object, or one if its subclasses # @param [optional, String, #read] body This should # be sent as "rack.input". If it's a String, it will @@ -42,7 +42,7 @@ module Artifice # @return [Net::HTTPResponse] # # @yield [Net::HTTPResponse] If a block is provided, - # this method will yield the Net::HTTPResponse to + # this method will yield the Gem::Net::HTTPResponse to # it after the body is read. def request(req, body = nil, &block) rack_request = RackRequest.new(self.class.endpoint) @@ -63,10 +63,10 @@ module Artifice private - # This method takes a Rack response and creates a Net::HTTPResponse + # This method takes a Rack response and creates a Gem::Net::HTTPResponse # Instead of trying to mock HTTPResponse directly, we just convert # the Rack response into a String that looks like a normal HTTP - # response and call Net::HTTPResponse.read_new + # response and call Gem::Net::HTTPResponse.read_new # # @param [Array(#to_i, Hash, #each)] response a Rack response # @return [Net::HTTPResponse] @@ -86,8 +86,8 @@ module Artifice response_string << "" << body - response_io = ::Net::BufferedIO.new(StringIO.new(response_string.join("\n"))) - res = ::Net::HTTPResponse.read_new(response_io) + response_io = ::Gem::Net::BufferedIO.new(StringIO.new(response_string.join("\n"))) + res = ::Gem::Net::HTTPResponse.read_new(response_io) res.reading_body(response_io, true) do yield res if block_given? diff --git a/spec/bundler/support/artifice/vcr.rb b/spec/bundler/support/artifice/vcr.rb index 740a000311..7b9a8bdeaf 100644 --- a/spec/bundler/support/artifice/vcr.rb +++ b/spec/bundler/support/artifice/vcr.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require "net/http" +require "bundler/vendored_net_http" require_relative "../path" CASSETTE_PATH = "#{Spec::Path.spec_dir}/support/artifice/vcr_cassettes".freeze USED_CASSETTES_PATH = "#{Spec::Path.spec_dir}/support/artifice/used_cassettes.txt".freeze CASSETTE_NAME = ENV.fetch("BUNDLER_SPEC_VCR_CASSETTE_NAME") { "realworld" } -class BundlerVCRHTTP < Net::HTTP +class BundlerVCRHTTP < Gem::Net::HTTP class RequestHandler attr_reader :http, :request, :body, :response_block def initialize(http, request, body = nil, &response_block) @@ -41,8 +41,8 @@ class BundlerVCRHTTP < Net::HTTP def recorded_response File.open(request_pair_paths.last, "rb:ASCII-8BIT") do |response_file| - response_io = ::Net::BufferedIO.new(response_file) - ::Net::HTTPResponse.read_new(response_io).tap do |response| + response_io = ::Gem::Net::BufferedIO.new(response_file) + ::Gem::Net::HTTPResponse.read_new(response_io).tap do |response| response.decode_content = request.decode_content if request.respond_to?(:decode_content) response.uri = request.uri @@ -148,5 +148,5 @@ end require_relative "helpers/artifice" -# Replace Net::HTTP with our VCR subclass +# Replace Gem::Net::HTTP with our VCR subclass Artifice.replace_net_http(BundlerVCRHTTP) |