@@ -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 = [ ]
@@ -48,12 +49,10 @@ def test_get
4849 certs . zip ( [ CA_CERT , SERVER_CERT ] [ -certs . size ..] ) do |actual , expected |
4950 assert_equal ( expected . to_der , actual . to_der )
5051 end
51- rescue SystemCallError
52- skip $!
5352 end
5453
5554 def test_get_SNI
56- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
55+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
5756 http . ipaddr = config ( 'host' )
5857 http . use_ssl = true
5958 http . cert_store = TEST_STORE
@@ -127,23 +126,21 @@ def test_get_SNI_failure
127126 end
128127
129128 def test_post
130- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
129+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
131130 http . use_ssl = true
132131 http . cert_store = TEST_STORE
133132 data = config ( 'ssl_private_key' ) . to_der
134133 http . request_post ( "/" , data , { 'content-type' => 'application/x-www-form-urlencoded' } ) { |res |
135134 assert_equal ( data , res . body )
136135 }
137- rescue SystemCallError
138- skip $!
139136 end
140137
141138 def test_session_reuse
142139 # FIXME: The new_session_cb is known broken for clients in OpenSSL 1.1.0h.
143140 # See https://github.com/openssl/openssl/pull/5967 for details.
144141 skip if OpenSSL ::OPENSSL_LIBRARY_VERSION =~ /OpenSSL 1.1.0h/
145142
146- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
143+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
147144 http . use_ssl = true
148145 http . cert_store = TEST_STORE
149146
@@ -166,15 +163,13 @@ def test_session_reuse
166163 assert_equal true , socket . session_reused?
167164
168165 http . finish
169- rescue SystemCallError
170- skip $!
171166 end
172167
173168 def test_session_reuse_but_expire
174169 # FIXME: The new_session_cb is known broken for clients in OpenSSL 1.1.0h.
175170 skip if OpenSSL ::OPENSSL_LIBRARY_VERSION =~ /OpenSSL 1.1.0h/
176171
177- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
172+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
178173 http . use_ssl = true
179174 http . cert_store = TEST_STORE
180175
@@ -190,8 +185,6 @@ def test_session_reuse_but_expire
190185 assert_equal false , socket . session_reused?
191186
192187 http . finish
193- rescue SystemCallError
194- skip $!
195188 end
196189
197190 if ENV [ "RUBY_OPENSSL_TEST_ALL" ]
@@ -206,14 +199,12 @@ def test_verify
206199 end
207200
208201 def test_verify_none
209- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
202+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
210203 http . use_ssl = true
211204 http . verify_mode = OpenSSL ::SSL ::VERIFY_NONE
212205 http . request_get ( "/" ) { |res |
213206 assert_equal ( $test_net_http_data, res . body )
214207 }
215- rescue SystemCallError
216- skip $!
217208 end
218209
219210 def test_skip_hostname_verification
@@ -242,14 +233,10 @@ def test_fail_if_verify_hostname_is_true
242233 end
243234
244235 def test_certificate_verify_failure
245- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
236+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
246237 http . use_ssl = true
247238 ex = assert_raise ( OpenSSL ::SSL ::SSLError ) {
248- begin
249- http . request_get ( "/" ) { |res | }
250- rescue SystemCallError
251- skip $!
252- end
239+ http . request_get ( "/" ) { |res | }
253240 }
254241 assert_match ( /certificate verify failed/ , ex . message )
255242 unless /mswin|mingw/ =~ RUBY_PLATFORM
@@ -279,10 +266,10 @@ def test_timeout_during_SSL_handshake
279266 bug4246 = "expected the SSL connection to have timed out but have not. [ruby-core:34203]"
280267
281268 # listen for connections... but deliberately do not complete SSL handshake
282- TCPServer . open ( 'localhost' , 0 ) { |server |
269+ TCPServer . open ( HOST , 0 ) { |server |
283270 port = server . addr [ 1 ]
284271
285- conn = Net ::HTTP . new ( 'localhost' , port )
272+ conn = Net ::HTTP . new ( HOST , port )
286273 conn . use_ssl = true
287274 conn . read_timeout = 0.01
288275 conn . open_timeout = 0.01
@@ -297,7 +284,7 @@ def test_timeout_during_SSL_handshake
297284 end
298285
299286 def test_min_version
300- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
287+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
301288 http . use_ssl = true
302289 http . min_version = :TLS1
303290 http . cert_store = TEST_STORE
0 commit comments