2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-10-15 20:14:16 -04:00
|
|
|
require 'rubygems/test_case'
|
2018-12-12 00:07:50 -05:00
|
|
|
require 'net/http'
|
2013-10-15 20:14:16 -04:00
|
|
|
require 'rubygems/request'
|
|
|
|
|
|
|
|
# = Testing Bundled CA
|
|
|
|
#
|
|
|
|
# The tested hosts are explained in detail here: https://github.com/rubygems/rubygems/commit/5e16a5428f973667cabfa07e94ff939e7a83ebd9
|
|
|
|
#
|
|
|
|
|
2016-06-18 01:11:55 -04:00
|
|
|
if ENV["CI"] || ENV["TEST_SSL"]
|
2016-02-01 07:43:26 -05:00
|
|
|
class TestBundledCA < Gem::TestCase
|
2013-10-15 20:14:16 -04:00
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
THIS_FILE = File.expand_path __FILE__
|
2013-10-15 20:14:16 -04:00
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
def bundled_certificate_store
|
|
|
|
store = OpenSSL::X509::Store.new
|
2013-10-15 20:14:16 -04:00
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
ssl_cert_glob =
|
2016-04-06 02:01:14 -04:00
|
|
|
File.expand_path '../../../lib/rubygems/ssl_certs/*/*.pem', THIS_FILE
|
2013-10-15 20:14:16 -04:00
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
Dir[ssl_cert_glob].each do |ssl_cert|
|
|
|
|
store.add_file ssl_cert
|
|
|
|
end
|
2013-10-15 20:14:16 -04:00
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
store
|
2013-10-15 20:14:16 -04:00
|
|
|
end
|
2016-02-01 07:43:26 -05:00
|
|
|
|
|
|
|
def assert_https(host)
|
|
|
|
if self.respond_to? :_assertions # minitest <= 4
|
|
|
|
self._assertions += 1
|
|
|
|
else # minitest >= 5
|
|
|
|
self.assertions += 1
|
|
|
|
end
|
|
|
|
http = Net::HTTP.new(host, 443)
|
|
|
|
http.use_ssl = true
|
|
|
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
|
|
http.cert_store = bundled_certificate_store
|
|
|
|
http.get('/')
|
|
|
|
rescue Errno::ENOENT, Errno::ETIMEDOUT
|
|
|
|
skip "#{host} seems offline, I can't tell whether ssl would work."
|
|
|
|
rescue OpenSSL::SSL::SSLError => e
|
|
|
|
# Only fail for certificate verification errors
|
|
|
|
if e.message =~ /certificate verify failed/
|
|
|
|
flunk "#{host} is not verifiable using the included certificates. Error was: #{e.message}"
|
|
|
|
end
|
|
|
|
raise
|
2013-10-15 20:14:16 -04:00
|
|
|
end
|
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
def test_accessing_rubygems
|
|
|
|
assert_https('rubygems.org')
|
|
|
|
end
|
2013-10-15 20:14:16 -04:00
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
def test_accessing_fastly
|
|
|
|
assert_https('rubygems.global.ssl.fastly.net')
|
|
|
|
end
|
2013-10-15 20:14:16 -04:00
|
|
|
|
2016-04-06 02:01:14 -04:00
|
|
|
def test_accessing_new_index
|
|
|
|
assert_https('fastly.rubygems.org')
|
|
|
|
end
|
|
|
|
|
2013-10-15 20:14:16 -04:00
|
|
|
end
|
2016-02-01 07:43:26 -05:00
|
|
|
end
|