Skip to content

Commit

Permalink
Fix test_https.rb host, Rakefile
Browse files Browse the repository at this point in the history
  • Loading branch information
MSP-Greg committed Apr 28, 2021
1 parent aea55e9 commit 93944f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 12 additions & 11 deletions test/net/http/test_https.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ 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"))
DHPARAMS = OpenSSL::PKey::DH.new(read_fixture("dhparams.pem"))
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,
Expand All @@ -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 = []
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 93944f5

Please sign in to comment.