[rubygems/rubygems] Diagnose the RubyGems connection
https://github.com/rubygems/rubygems/commit/bf63859e1e
This commit is contained in:
parent
cba7408017
commit
7a10ce8c95
@ -1,5 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "rubygems/remote_fetcher"
|
||||||
require "uri"
|
require "uri"
|
||||||
|
|
||||||
module Bundler
|
module Bundler
|
||||||
@ -15,6 +16,7 @@ module Bundler
|
|||||||
|
|
||||||
output_ssl_environment
|
output_ssl_environment
|
||||||
bundler_success = bundler_connection_successful?
|
bundler_success = bundler_connection_successful?
|
||||||
|
rubygem_success = rubygem_connection_successful?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -79,6 +81,17 @@ module Bundler
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rubygem_connection_successful?
|
||||||
|
Gem::RemoteFetcher.fetcher.fetch_path(uri)
|
||||||
|
Bundler.ui.info("RubyGems: success")
|
||||||
|
|
||||||
|
true
|
||||||
|
rescue StandardError => error
|
||||||
|
Bundler.ui.warn("RubyGems: failed (#{Explanation.explain_bundler_or_rubygems_error(error)})")
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
module Explanation
|
module Explanation
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
|
@ -43,15 +43,6 @@ def show_ssl_certs
|
|||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
|
||||||
require 'rubygems/remote_fetcher'
|
|
||||||
Gem::RemoteFetcher.fetcher.fetch_path(uri)
|
|
||||||
rubygems_status = "✅ success"
|
|
||||||
rescue => error
|
|
||||||
rubygems_status = "❌ failed (#{error_reason(error)})"
|
|
||||||
end
|
|
||||||
puts "RubyGems: #{rubygems_status}"
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# Try to connect using HTTPS
|
# Try to connect using HTTPS
|
||||||
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
||||||
|
@ -18,13 +18,16 @@ RSpec.describe "bundle doctor ssl" do
|
|||||||
|
|
||||||
@previous_level = Bundler.ui.level
|
@previous_level = Bundler.ui.level
|
||||||
Bundler.ui.instance_variable_get(:@warning_history).clear
|
Bundler.ui.instance_variable_get(:@warning_history).clear
|
||||||
|
@previous_client = Gem::Request::ConnectionPools.client
|
||||||
Bundler.ui.level = "info"
|
Bundler.ui.level = "info"
|
||||||
Artifice.activate_with(@dummy_endpoint)
|
Artifice.activate_with(@dummy_endpoint)
|
||||||
|
Gem::Request::ConnectionPools.client = Gem::Net::HTTP
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:each) do
|
after(:each) do
|
||||||
Bundler.ui.level = @previous_level
|
Bundler.ui.level = @previous_level
|
||||||
Artifice.deactivate
|
Artifice.deactivate
|
||||||
|
Gem::Request::ConnectionPools.client = @previous_client
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when a diagnostic fails" do
|
context "when a diagnostic fails" do
|
||||||
@ -48,6 +51,8 @@ RSpec.describe "bundle doctor ssl" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
Artifice.replace_net_http(net_http)
|
Artifice.replace_net_http(net_http)
|
||||||
|
Gem::Request::ConnectionPools.client = net_http
|
||||||
|
Gem::RemoteFetcher.fetcher.close_all
|
||||||
|
|
||||||
expected_out = <<~MSG
|
expected_out = <<~MSG
|
||||||
Here's your OpenSSL environment:
|
Here's your OpenSSL environment:
|
||||||
@ -61,6 +66,7 @@ RSpec.describe "bundle doctor ssl" do
|
|||||||
|
|
||||||
expected_err = <<~MSG
|
expected_err = <<~MSG
|
||||||
Bundler: failed (certificate verification)
|
Bundler: failed (certificate verification)
|
||||||
|
RubyGems: failed (certificate verification)
|
||||||
|
|
||||||
MSG
|
MSG
|
||||||
|
|
||||||
@ -78,6 +84,8 @@ RSpec.describe "bundle doctor ssl" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
Artifice.replace_net_http(net_http)
|
Artifice.replace_net_http(net_http)
|
||||||
|
Gem::Request::ConnectionPools.client = Gem::Net::HTTP
|
||||||
|
Gem::RemoteFetcher.fetcher.close_all
|
||||||
|
|
||||||
expected_out = <<~MSG
|
expected_out = <<~MSG
|
||||||
Here's your OpenSSL environment:
|
Here's your OpenSSL environment:
|
||||||
@ -91,6 +99,7 @@ RSpec.describe "bundle doctor ssl" do
|
|||||||
|
|
||||||
expected_err = <<~MSG
|
expected_err = <<~MSG
|
||||||
Bundler: failed (SSL/TLS protocol version mismatch)
|
Bundler: failed (SSL/TLS protocol version mismatch)
|
||||||
|
RubyGems: failed (SSL/TLS protocol version mismatch)
|
||||||
|
|
||||||
MSG
|
MSG
|
||||||
|
|
||||||
@ -109,6 +118,7 @@ RSpec.describe "bundle doctor ssl" do
|
|||||||
|
|
||||||
Trying connections to https://rubygems.org:
|
Trying connections to https://rubygems.org:
|
||||||
Bundler: success
|
Bundler: success
|
||||||
|
RubyGems: success
|
||||||
|
|
||||||
MSG
|
MSG
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user