diff --git a/Rakefile b/Rakefile index d81dd1f4..191c2fc9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,9 @@ -require "bundler/gem_tasks" +require "bundler/gem_tasks" if defined?(Bundler) require "rake/testtask" Rake::TestTask.new(:test) do |t| - t.libs << "test/lib" + t.libs << "./test/lib" + t.ruby_opts << "-rhelper" t.test_files = FileList["test/**/test_*.rb"] end diff --git a/test/net/http/test_https.rb b/test/net/http/test_https.rb index e9aee15b..7e6ad6ed 100644 --- a/test/net/http/test_https.rb +++ b/test/net/http/test_https.rb @@ -16,6 +16,7 @@ def self.read_fixture(key) File.read(File.expand_path("../fixtures/#{key}", __dir__)) end + HOST = 'localhost' CA_CERT = OpenSSL::X509::Certificate.new(read_fixture("cacert.pem")) SERVER_KEY = OpenSSL::PKey.read(read_fixture("server.key")) SERVER_CERT = OpenSSL::X509::Certificate.new(read_fixture("server.crt")) @@ -23,7 +24,7 @@ def self.read_fixture(key) TEST_STORE = OpenSSL::X509::Store.new.tap {|s| s.add_cert(CA_CERT) } CONFIG = { - 'host' => '127.0.0.1', + 'host' => HOST, 'proxy_host' => nil, 'proxy_port' => nil, 'ssl_enable' => true, @@ -33,7 +34,7 @@ def self.read_fixture(key) } def test_get - http = Net::HTTP.new("localhost", config("port")) + http = Net::HTTP.new(HOST, config("port")) http.use_ssl = true http.cert_store = TEST_STORE certs = [] @@ -53,7 +54,7 @@ def test_get end def test_get_SNI - http = Net::HTTP.new("localhost", config("port")) + http = Net::HTTP.new(HOST, config("port")) http.ipaddr = config('host') http.use_ssl = true http.cert_store = TEST_STORE @@ -127,7 +128,7 @@ def test_get_SNI_failure end def test_post - http = Net::HTTP.new("localhost", config("port")) + http = Net::HTTP.new(HOST, config("port")) http.use_ssl = true http.cert_store = TEST_STORE data = config('ssl_private_key').to_der @@ -143,7 +144,7 @@ def test_session_reuse # See https://github.com/openssl/openssl/pull/5967 for details. skip if OpenSSL::OPENSSL_LIBRARY_VERSION =~ /OpenSSL 1.1.0h/ - http = Net::HTTP.new("localhost", config("port")) + http = Net::HTTP.new(HOST, config("port")) http.use_ssl = true http.cert_store = TEST_STORE @@ -174,7 +175,7 @@ def test_session_reuse_but_expire # FIXME: The new_session_cb is known broken for clients in OpenSSL 1.1.0h. skip if OpenSSL::OPENSSL_LIBRARY_VERSION =~ /OpenSSL 1.1.0h/ - http = Net::HTTP.new("localhost", config("port")) + http = Net::HTTP.new(HOST, config("port")) http.use_ssl = true http.cert_store = TEST_STORE @@ -206,7 +207,7 @@ def test_verify end def test_verify_none - http = Net::HTTP.new("localhost", config("port")) + http = Net::HTTP.new(HOST, config("port")) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.request_get("/") {|res| @@ -242,7 +243,7 @@ def test_fail_if_verify_hostname_is_true end def test_certificate_verify_failure - http = Net::HTTP.new("localhost", config("port")) + http = Net::HTTP.new(HOST, config("port")) http.use_ssl = true ex = assert_raise(OpenSSL::SSL::SSLError){ begin @@ -279,10 +280,10 @@ def test_timeout_during_SSL_handshake bug4246 = "expected the SSL connection to have timed out but have not. [ruby-core:34203]" # listen for connections... but deliberately do not complete SSL handshake - TCPServer.open('localhost', 0) {|server| + TCPServer.open(HOST, 0) {|server| port = server.addr[1] - conn = Net::HTTP.new('localhost', port) + conn = Net::HTTP.new(HOST, port) conn.use_ssl = true conn.read_timeout = 0.01 conn.open_timeout = 0.01 @@ -297,7 +298,7 @@ def test_timeout_during_SSL_handshake end def test_min_version - http = Net::HTTP.new("localhost", config("port")) + http = Net::HTTP.new(HOST, config("port")) http.use_ssl = true http.min_version = :TLS1 http.cert_store = TEST_STORE