summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdouard CHIN <[email protected]>2025-04-09 23:59:48 +0200
committerHiroshi SHIBATA <[email protected]>2025-04-22 11:27:23 +0900
commit7a10ce8c95a714e6eb37250687828508e133dddc (patch)
treed1ca3874dac9b3b8df8420682bea9475a223416d
parentcba7408017e51e6ef119964f1b408e4938c8a2a4 (diff)
[rubygems/rubygems] Diagnose the RubyGems connection
https://github.com/rubygems/rubygems/commit/bf63859e1e
-rw-r--r--lib/bundler/cli/doctor/ssl.rb13
-rw-r--r--libexec/ssl_check.rb9
-rw-r--r--spec/bundler/commands/ssl_spec.rb10
3 files changed, 23 insertions, 9 deletions
diff --git a/lib/bundler/cli/doctor/ssl.rb b/lib/bundler/cli/doctor/ssl.rb
index 6742991122..f0d8a9b986 100644
--- a/lib/bundler/cli/doctor/ssl.rb
+++ b/lib/bundler/cli/doctor/ssl.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
+require "rubygems/remote_fetcher"
require "uri"
module Bundler
@@ -15,6 +16,7 @@ module Bundler
output_ssl_environment
bundler_success = bundler_connection_successful?
+ rubygem_success = rubygem_connection_successful?
end
private
@@ -79,6 +81,17 @@ module Bundler
false
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
extend self
diff --git a/libexec/ssl_check.rb b/libexec/ssl_check.rb
index 1066e1f29b..39f60c47a1 100644
--- a/libexec/ssl_check.rb
+++ b/libexec/ssl_check.rb
@@ -44,15 +44,6 @@ def show_ssl_certs
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
# Try to connect using HTTPS
Net::HTTP.new(uri.host, uri.port).tap do |http|
http.use_ssl = true
diff --git a/spec/bundler/commands/ssl_spec.rb b/spec/bundler/commands/ssl_spec.rb
index fc3e0c61cd..1172bc9da7 100644
--- a/spec/bundler/commands/ssl_spec.rb
+++ b/spec/bundler/commands/ssl_spec.rb
@@ -18,13 +18,16 @@ RSpec.describe "bundle doctor ssl" do
@previous_level = Bundler.ui.level
Bundler.ui.instance_variable_get(:@warning_history).clear
+ @previous_client = Gem::Request::ConnectionPools.client
Bundler.ui.level = "info"
Artifice.activate_with(@dummy_endpoint)
+ Gem::Request::ConnectionPools.client = Gem::Net::HTTP
end
after(:each) do
Bundler.ui.level = @previous_level
Artifice.deactivate
+ Gem::Request::ConnectionPools.client = @previous_client
end
context "when a diagnostic fails" do
@@ -48,6 +51,8 @@ RSpec.describe "bundle doctor ssl" do
end
Artifice.replace_net_http(net_http)
+ Gem::Request::ConnectionPools.client = net_http
+ Gem::RemoteFetcher.fetcher.close_all
expected_out = <<~MSG
Here's your OpenSSL environment:
@@ -61,6 +66,7 @@ RSpec.describe "bundle doctor ssl" do
expected_err = <<~MSG
Bundler: failed (certificate verification)
+ RubyGems: failed (certificate verification)
MSG
@@ -78,6 +84,8 @@ RSpec.describe "bundle doctor ssl" do
end
Artifice.replace_net_http(net_http)
+ Gem::Request::ConnectionPools.client = Gem::Net::HTTP
+ Gem::RemoteFetcher.fetcher.close_all
expected_out = <<~MSG
Here's your OpenSSL environment:
@@ -91,6 +99,7 @@ RSpec.describe "bundle doctor ssl" do
expected_err = <<~MSG
Bundler: failed (SSL/TLS protocol version mismatch)
+ RubyGems: failed (SSL/TLS protocol version mismatch)
MSG
@@ -109,6 +118,7 @@ RSpec.describe "bundle doctor ssl" do
Trying connections to https://rubygems.org:
Bundler: success
+ RubyGems: success
MSG