Skip to content

Commit cda2929

Browse files
Edouard-chinhsbt
authored andcommitted
[rubygems/rubygems] Add the bundle doctor subcommand skeleton:
- The command can either be run using: 1. `bundle doctor --ssl` 2. `bundle doctor ssl` The later is most useful when you need to specify custom ssl options (such as the verify mode or the TLS version when running the diagnostic). The implementation will follow in the next commits. rubygems/rubygems@993d12874c
1 parent c2e58a9 commit cda2929

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed

lib/bundler/cli/doctor.rb

+13
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,22 @@ class CLI::Doctor < Thor
1212
D
1313
method_option "gemfile", type: :string, banner: "Use the specified gemfile instead of Gemfile"
1414
method_option "quiet", type: :boolean, banner: "Only output warnings and errors."
15+
method_option "ssl", type: :boolean, default: false, banner: "Diagnose SSL problems."
1516
def diagnose
1617
require_relative "doctor/diagnose"
1718
Diagnose.new(options).run
1819
end
20+
21+
desc "ssl [OPTIONS]", "Diagnose SSL problems"
22+
long_desc <<-D
23+
Diagnose SSL problems, especially related to certificates or TLS version while connecting to https://rubygems.org.
24+
D
25+
method_option "host", type: :string, banner: "The host to diagnose."
26+
method_option "tls-version", type: :string, banner: "Specify the SSL/TLS version when running the diagnostic. Accepts either <1.1> or <1.2>"
27+
method_option "verify-mode", type: :string, banner: "Specify the mode used for certification verification. Accepts either <peer> or <none>"
28+
def ssl
29+
require_relative "doctor/ssl"
30+
SSL.new(options).run
31+
end
1932
end
2033
end

lib/bundler/cli/doctor/diagnose.rb

+6
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ def check!
6969
Bundler::CLI::Check.new({}).run
7070
end
7171

72+
def diagnose_ssl
73+
require_relative "ssl"
74+
Bundler::CLI::Doctor::SSL.new({}).run
75+
end
76+
7277
def run
7378
Bundler.ui.level = "warn" if options[:quiet]
7479
Bundler.settings.validate!
7580
check!
81+
diagnose_ssl if options[:ssl]
7682

7783
definition = Bundler.definition
7884
broken_links = {}

lib/bundler/cli/doctor/ssl.rb

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
module Bundler
4+
class CLI::Doctor::SSL
5+
attr_reader :options
6+
7+
def initialize(options)
8+
@options = options
9+
end
10+
11+
def run
12+
end
13+
14+
private
15+
16+
def host
17+
@options[:host] || "rubygems.org"
18+
end
19+
20+
def tls_version
21+
@options[:"tls-version"].then do |version|
22+
"TLS#{version.sub(".", "_")}".to_sym if version
23+
end
24+
end
25+
26+
def verify_mode
27+
mode = @options[:"verify-mode"] || :peer
28+
29+
@verify_mode ||= mode.then {|mod| OpenSSL::SSL.const_get("verify_#{mod}".upcase) }
30+
end
31+
end
32+
end

libexec/ssl_check.rb

-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
#!/usr/bin/env ruby
22
# Encoding: utf-8
33

4-
if RUBY_VERSION < "2.7"
5-
warn "!!! WARNING !!!",
6-
"Ruby #{RUBY_VERSION} has reached end-of-life, and is unsupported.",
7-
"This script may not work.",
8-
""
9-
end
10-
11-
if ARGV.include?("-h") || ARGV.include?("--help")
12-
puts "USAGE: check.rb [HOSTNAME] [TLS_VERSION] [VERIFY]"
13-
puts " default: check.rb rubygems.org auto VERIFY_PEER"
14-
puts " example: check.rb github.com TLSv1_2 VERIFY_NONE"
15-
exit 0
16-
end
17-
18-
host = ARGV.shift || "rubygems.org"
19-
204
require 'uri'
215
require 'net/http'
226

@@ -40,8 +24,6 @@
4024
end
4125

4226
uri = URI("https://#{host}")
43-
tls_version = ARGV.shift
44-
verify_mode = ARGV.any? ? OpenSSL::SSL.const_get(ARGV.shift) : OpenSSL::SSL::VERIFY_PEER
4527

4628
if defined?(RUBY_DESCRIPTION)
4729
ruby_version = RUBY_DESCRIPTION

spec/bundler/commands/ssl_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/cli"
4+
require "bundler/cli/doctor"
5+
require "bundler/cli/doctor/ssl"
6+
7+
RSpec.describe "bundle doctor ssl" do
8+
end

0 commit comments

Comments
 (0)