@@ -16,14 +16,15 @@ def self.read_fixture(key)
16
16
File . read ( File . expand_path ( "../fixtures/#{ key } " , __dir__ ) )
17
17
end
18
18
19
+ HOST = 'localhost'
19
20
CA_CERT = OpenSSL ::X509 ::Certificate . new ( read_fixture ( "cacert.pem" ) )
20
21
SERVER_KEY = OpenSSL ::PKey . read ( read_fixture ( "server.key" ) )
21
22
SERVER_CERT = OpenSSL ::X509 ::Certificate . new ( read_fixture ( "server.crt" ) )
22
23
DHPARAMS = OpenSSL ::PKey ::DH . new ( read_fixture ( "dhparams.pem" ) )
23
24
TEST_STORE = OpenSSL ::X509 ::Store . new . tap { |s | s . add_cert ( CA_CERT ) }
24
25
25
26
CONFIG = {
26
- 'host' => '127.0.0.1' ,
27
+ 'host' => HOST ,
27
28
'proxy_host' => nil ,
28
29
'proxy_port' => nil ,
29
30
'ssl_enable' => true ,
@@ -33,7 +34,7 @@ def self.read_fixture(key)
33
34
}
34
35
35
36
def test_get
36
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
37
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
37
38
http . use_ssl = true
38
39
http . cert_store = TEST_STORE
39
40
certs = [ ]
@@ -53,7 +54,7 @@ def test_get
53
54
end
54
55
55
56
def test_get_SNI
56
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
57
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
57
58
http . ipaddr = config ( 'host' )
58
59
http . use_ssl = true
59
60
http . cert_store = TEST_STORE
@@ -127,7 +128,7 @@ def test_get_SNI_failure
127
128
end
128
129
129
130
def test_post
130
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
131
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
131
132
http . use_ssl = true
132
133
http . cert_store = TEST_STORE
133
134
data = config ( 'ssl_private_key' ) . to_der
@@ -143,7 +144,7 @@ def test_session_reuse
143
144
# See https://github.com/openssl/openssl/pull/5967 for details.
144
145
skip if OpenSSL ::OPENSSL_LIBRARY_VERSION =~ /OpenSSL 1.1.0h/
145
146
146
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
147
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
147
148
http . use_ssl = true
148
149
http . cert_store = TEST_STORE
149
150
@@ -174,7 +175,7 @@ def test_session_reuse_but_expire
174
175
# FIXME: The new_session_cb is known broken for clients in OpenSSL 1.1.0h.
175
176
skip if OpenSSL ::OPENSSL_LIBRARY_VERSION =~ /OpenSSL 1.1.0h/
176
177
177
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
178
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
178
179
http . use_ssl = true
179
180
http . cert_store = TEST_STORE
180
181
@@ -206,7 +207,7 @@ def test_verify
206
207
end
207
208
208
209
def test_verify_none
209
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
210
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
210
211
http . use_ssl = true
211
212
http . verify_mode = OpenSSL ::SSL ::VERIFY_NONE
212
213
http . request_get ( "/" ) { |res |
@@ -242,7 +243,7 @@ def test_fail_if_verify_hostname_is_true
242
243
end
243
244
244
245
def test_certificate_verify_failure
245
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
246
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
246
247
http . use_ssl = true
247
248
ex = assert_raise ( OpenSSL ::SSL ::SSLError ) {
248
249
begin
@@ -279,10 +280,10 @@ def test_timeout_during_SSL_handshake
279
280
bug4246 = "expected the SSL connection to have timed out but have not. [ruby-core:34203]"
280
281
281
282
# listen for connections... but deliberately do not complete SSL handshake
282
- TCPServer . open ( 'localhost' , 0 ) { |server |
283
+ TCPServer . open ( HOST , 0 ) { |server |
283
284
port = server . addr [ 1 ]
284
285
285
- conn = Net ::HTTP . new ( 'localhost' , port )
286
+ conn = Net ::HTTP . new ( HOST , port )
286
287
conn . use_ssl = true
287
288
conn . read_timeout = 0.01
288
289
conn . open_timeout = 0.01
@@ -297,7 +298,7 @@ def test_timeout_during_SSL_handshake
297
298
end
298
299
299
300
def test_min_version
300
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
301
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
301
302
http . use_ssl = true
302
303
http . min_version = :TLS1
303
304
http . cert_store = TEST_STORE
0 commit comments