1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

skip OpenSSL dependent tests if not available

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-04-23 13:48:41 +00:00
parent 535a28c737
commit 77b1d88513
4 changed files with 34 additions and 32 deletions

View file

@ -45,8 +45,8 @@ class IMAPTest < Test::Unit::TestCase
assert_match(/\A24-Jul-2009 01:23 [+\-]\d{4}\z/, s) assert_match(/\A24-Jul-2009 01:23 [+\-]\d{4}\z/, s)
end end
def test_imaps_unknown_ca if defined?(OpenSSL::SSL::SSLError)
if defined?(OpenSSL) def test_imaps_unknown_ca
assert_raise(OpenSSL::SSL::SSLError) do assert_raise(OpenSSL::SSL::SSLError) do
imaps_test do |port| imaps_test do |port|
begin begin
@ -59,10 +59,8 @@ class IMAPTest < Test::Unit::TestCase
end end
end end
end end
end
def test_imaps_with_ca_file def test_imaps_with_ca_file
if defined?(OpenSSL)
assert_nothing_raised do assert_nothing_raised do
imaps_test do |port| imaps_test do |port|
begin begin
@ -75,10 +73,8 @@ class IMAPTest < Test::Unit::TestCase
end end
end end
end end
end
def test_imaps_verify_none def test_imaps_verify_none
if defined?(OpenSSL)
assert_nothing_raised do assert_nothing_raised do
imaps_test do |port| imaps_test do |port|
Net::IMAP.new(SERVER_ADDR, Net::IMAP.new(SERVER_ADDR,
@ -87,10 +83,8 @@ class IMAPTest < Test::Unit::TestCase
end end
end end
end end
end
def test_imaps_post_connection_check def test_imaps_post_connection_check
if defined?(OpenSSL)
assert_raise(OpenSSL::SSL::SSLError) do assert_raise(OpenSSL::SSL::SSLError) do
imaps_test do |port| imaps_test do |port|
# SERVER_ADDR is different from the hostname in the certificate, # SERVER_ADDR is different from the hostname in the certificate,
@ -103,20 +97,20 @@ class IMAPTest < Test::Unit::TestCase
end end
end end
def test_starttls if defined?(OpenSSL::SSL)
imap = nil def test_starttls
if defined?(OpenSSL) imap = nil
starttls_test do |port| starttls_test do |port|
imap = Net::IMAP.new("localhost", :port => port) imap = Net::IMAP.new("localhost", :port => port)
imap.starttls(:ca_file => CA_FILE) imap.starttls(:ca_file => CA_FILE)
imap imap
end end
end rescue SystemCallError
rescue SystemCallError skip $!
skip $! ensure
ensure if imap && !imap.disconnected?
if imap && !imap.disconnected? imap.disconnect
imap.disconnect end
end end
end end

View file

@ -1,13 +1,18 @@
require 'test/unit' require 'test/unit'
require 'open-uri' require 'open-uri'
require 'openssl'
require 'stringio' require 'stringio'
require 'webrick' require 'webrick'
require 'webrick/https' begin
require 'openssl'
require 'webrick/https'
rescue LoadError
end
require 'webrick/httpproxy' require 'webrick/httpproxy'
class TestOpenURISSL < Test::Unit::TestCase class TestOpenURISSL < Test::Unit::TestCase
end
class TestOpenURISSL
NullLog = Object.new NullLog = Object.new
def NullLog.<<(arg) def NullLog.<<(arg)
end end
@ -100,7 +105,7 @@ class TestOpenURISSL < Test::Unit::TestCase
} }
end end
end end if defined?(OpenSSL)
# mkdir demoCA demoCA/private demoCA/newcerts # mkdir demoCA demoCA/private demoCA/newcerts
# touch demoCA/index.txt # touch demoCA/index.txt

View file

@ -1,7 +1,10 @@
require 'rubygems/test_case' require 'rubygems/test_case'
require 'ostruct' require 'ostruct'
require 'webrick' require 'webrick'
require 'webrick/https' begin
require 'webrick/https'
rescue LoadError
end
require 'rubygems/remote_fetcher' require 'rubygems/remote_fetcher'
require 'rubygems/format' require 'rubygems/format'
@ -749,7 +752,7 @@ gems:
with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher| with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher|
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
end end
end end if defined?(OpenSSL::PKey)
def test_do_not_allow_insecure_ssl_connection_by_default def test_do_not_allow_insecure_ssl_connection_by_default
ssl_server = self.class.start_ssl_server ssl_server = self.class.start_ssl_server
@ -758,14 +761,14 @@ gems:
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
end end
end end
end end if defined?(OpenSSL::PKey)
def test_ssl_connection_allow_verify_none def test_ssl_connection_allow_verify_none
ssl_server = self.class.start_ssl_server ssl_server = self.class.start_ssl_server
with_configured_fetcher(":ssl_verify_mode: 0") do |fetcher| with_configured_fetcher(":ssl_verify_mode: 0") do |fetcher|
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
end end
end end if defined?(OpenSSL::PKey)
def test_do_not_follow_insecure_redirect def test_do_not_follow_insecure_redirect
ssl_server = self.class.start_ssl_server ssl_server = self.class.start_ssl_server
@ -775,7 +778,7 @@ gems:
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/insecure_redirect?to=#{@server_uri}") fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/insecure_redirect?to=#{@server_uri}")
end end
end end
end end if defined?(OpenSSL::PKey)
def with_configured_fetcher(config_str = nil, &block) def with_configured_fetcher(config_str = nil, &block)
if config_str if config_str
@ -853,7 +856,7 @@ gems:
end end
DIR = File.expand_path(File.dirname(__FILE__)) DIR = File.expand_path(File.dirname(__FILE__))
DH_PARAM = OpenSSL::PKey::DH.new(128) DH_PARAM = defined?(OpenSSL::PKey) ? OpenSSL::PKey::DH.new(128) : nil
def start_ssl_server(config = {}) def start_ssl_server(config = {})
null_logger = NilLog.new null_logger = NilLog.new
@ -891,7 +894,7 @@ gems:
end end
end end
server server
end end if DH_PARAM

View file

@ -102,7 +102,7 @@ module XMLRPC
refute user refute user
refute password refute password
refute timeout refute timeout
end end if defined?(OpenSSL)
def test_new2_ssl_custom_port def test_new2_ssl_custom_port
client = Fake::Client.new2 'https://example.org:1234/foo' client = Fake::Client.new2 'https://example.org:1234/foo'
@ -117,7 +117,7 @@ module XMLRPC
refute user refute user
refute password refute password
refute timeout refute timeout
end end if defined?(OpenSSL)
def test_new2_user_password def test_new2_user_password
client = Fake::Client.new2 'http://aaron:tenderlove@example.org/foo' client = Fake::Client.new2 'http://aaron:tenderlove@example.org/foo'