Skip to content

Commit 93944f5

Browse files
committed
Fix test_https.rb host, Rakefile
1 parent aea55e9 commit 93944f5

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

Rakefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
require "bundler/gem_tasks"
1+
require "bundler/gem_tasks" if defined?(Bundler)
22
require "rake/testtask"
33

44
Rake::TestTask.new(:test) do |t|
5-
t.libs << "test/lib"
5+
t.libs << "./test/lib"
6+
67
t.ruby_opts << "-rhelper"
78
t.test_files = FileList["test/**/test_*.rb"]
89
end

test/net/http/test_https.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ def self.read_fixture(key)
1616
File.read(File.expand_path("../fixtures/#{key}", __dir__))
1717
end
1818

19+
HOST = 'localhost'
1920
CA_CERT = OpenSSL::X509::Certificate.new(read_fixture("cacert.pem"))
2021
SERVER_KEY = OpenSSL::PKey.read(read_fixture("server.key"))
2122
SERVER_CERT = OpenSSL::X509::Certificate.new(read_fixture("server.crt"))
2223
DHPARAMS = OpenSSL::PKey::DH.new(read_fixture("dhparams.pem"))
2324
TEST_STORE = OpenSSL::X509::Store.new.tap {|s| s.add_cert(CA_CERT) }
2425

2526
CONFIG = {
26-
'host' => '127.0.0.1',
27+
'host' => HOST,
2728
'proxy_host' => nil,
2829
'proxy_port' => nil,
2930
'ssl_enable' => true,
@@ -33,7 +34,7 @@ def self.read_fixture(key)
3334
}
3435

3536
def test_get
36-
http = Net::HTTP.new("localhost", config("port"))
37+
http = Net::HTTP.new(HOST, config("port"))
3738
http.use_ssl = true
3839
http.cert_store = TEST_STORE
3940
certs = []
@@ -53,7 +54,7 @@ def test_get
5354
end
5455

5556
def test_get_SNI
56-
http = Net::HTTP.new("localhost", config("port"))
57+
http = Net::HTTP.new(HOST, config("port"))
5758
http.ipaddr = config('host')
5859
http.use_ssl = true
5960
http.cert_store = TEST_STORE
@@ -127,7 +128,7 @@ def test_get_SNI_failure
127128
end
128129

129130
def test_post
130-
http = Net::HTTP.new("localhost", config("port"))
131+
http = Net::HTTP.new(HOST, config("port"))
131132
http.use_ssl = true
132133
http.cert_store = TEST_STORE
133134
data = config('ssl_private_key').to_der
@@ -143,7 +144,7 @@ def test_session_reuse
143144
# See https://github.com/openssl/openssl/pull/5967 for details.
144145
skip if OpenSSL::OPENSSL_LIBRARY_VERSION =~ /OpenSSL 1.1.0h/
145146

146-
http = Net::HTTP.new("localhost", config("port"))
147+
http = Net::HTTP.new(HOST, config("port"))
147148
http.use_ssl = true
148149
http.cert_store = TEST_STORE
149150

@@ -174,7 +175,7 @@ def test_session_reuse_but_expire
174175
# FIXME: The new_session_cb is known broken for clients in OpenSSL 1.1.0h.
175176
skip if OpenSSL::OPENSSL_LIBRARY_VERSION =~ /OpenSSL 1.1.0h/
176177

177-
http = Net::HTTP.new("localhost", config("port"))
178+
http = Net::HTTP.new(HOST, config("port"))
178179
http.use_ssl = true
179180
http.cert_store = TEST_STORE
180181

@@ -206,7 +207,7 @@ def test_verify
206207
end
207208

208209
def test_verify_none
209-
http = Net::HTTP.new("localhost", config("port"))
210+
http = Net::HTTP.new(HOST, config("port"))
210211
http.use_ssl = true
211212
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
212213
http.request_get("/") {|res|
@@ -242,7 +243,7 @@ def test_fail_if_verify_hostname_is_true
242243
end
243244

244245
def test_certificate_verify_failure
245-
http = Net::HTTP.new("localhost", config("port"))
246+
http = Net::HTTP.new(HOST, config("port"))
246247
http.use_ssl = true
247248
ex = assert_raise(OpenSSL::SSL::SSLError){
248249
begin
@@ -279,10 +280,10 @@ def test_timeout_during_SSL_handshake
279280
bug4246 = "expected the SSL connection to have timed out but have not. [ruby-core:34203]"
280281

281282
# listen for connections... but deliberately do not complete SSL handshake
282-
TCPServer.open('localhost', 0) {|server|
283+
TCPServer.open(HOST, 0) {|server|
283284
port = server.addr[1]
284285

285-
conn = Net::HTTP.new('localhost', port)
286+
conn = Net::HTTP.new(HOST, port)
286287
conn.use_ssl = true
287288
conn.read_timeout = 0.01
288289
conn.open_timeout = 0.01
@@ -297,7 +298,7 @@ def test_timeout_during_SSL_handshake
297298
end
298299

299300
def test_min_version
300-
http = Net::HTTP.new("localhost", config("port"))
301+
http = Net::HTTP.new(HOST, config("port"))
301302
http.use_ssl = true
302303
http.min_version = :TLS1
303304
http.cert_store = TEST_STORE

0 commit comments

Comments
 (0)