Skip to content

Commit d41f086

Browse files
Hannes Georgdrbrain
authored andcommitted
Added a test for the included certificates
1 parent 4572bb0 commit d41f086

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/rubygems/test_bundled_ca.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require 'rubygems/test_case'
2+
require 'net/https'
3+
require 'rubygems/request'
4+
5+
# = Testing Bundled CA
6+
#
7+
# The tested hosts are explained in detail here: https://github.com/rubygems/rubygems/commit/5e16a5428f973667cabfa07e94ff939e7a83ebd9
8+
#
9+
class TestBundledCA < Gem::TestCase
10+
11+
def bundled_certificate_store
12+
store = OpenSSL::X509::Store.new
13+
req = Gem::Request.new(nil,nil,nil,:no_proxy)
14+
req.add_rubygems_trusted_certs(store)
15+
store
16+
end
17+
18+
def assert_https(host)
19+
if self.respond_to? :_assertions # minitest <= 4
20+
self._assertions += 1
21+
else # minitest >= 5
22+
self.assertions += 1
23+
end
24+
http = Net::HTTP.new(host, 443)
25+
http.use_ssl = true
26+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
27+
http.cert_store = bundled_certificate_store
28+
http.get('/')
29+
rescue Errno::ENOENT
30+
skip "#{host} seems offline, I can't tell whether ssl would work."
31+
rescue OpenSSL::SSL::SSLError => e
32+
# Only fail for certificate verification errors
33+
if e.message =~ /certificate verify failed/
34+
flunk "#{host} is not verifiable using the included certificates. Error was: #{e.message}"
35+
end
36+
raise
37+
end
38+
39+
def test_accessing_rubygems
40+
assert_https('rubygems.org')
41+
end
42+
43+
def test_accessing_cloudfront
44+
assert_https('d2chzxaqi4y7f8.cloudfront.net')
45+
end
46+
47+
def test_accessing_s3
48+
assert_https('s3.amazonaws.com')
49+
end
50+
51+
end

0 commit comments

Comments
 (0)