@@ -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 = [ ]
@@ -48,12 +49,10 @@ def test_get
48
49
certs . zip ( [ CA_CERT , SERVER_CERT ] [ -certs . size ..] ) do |actual , expected |
49
50
assert_equal ( expected . to_der , actual . to_der )
50
51
end
51
- rescue SystemCallError
52
- skip $!
53
52
end
54
53
55
54
def test_get_SNI
56
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
55
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
57
56
http . ipaddr = config ( 'host' )
58
57
http . use_ssl = true
59
58
http . cert_store = TEST_STORE
@@ -127,23 +126,21 @@ def test_get_SNI_failure
127
126
end
128
127
129
128
def test_post
130
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
129
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
131
130
http . use_ssl = true
132
131
http . cert_store = TEST_STORE
133
132
data = config ( 'ssl_private_key' ) . to_der
134
133
http . request_post ( "/" , data , { 'content-type' => 'application/x-www-form-urlencoded' } ) { |res |
135
134
assert_equal ( data , res . body )
136
135
}
137
- rescue SystemCallError
138
- skip $!
139
136
end
140
137
141
138
def test_session_reuse
142
139
# FIXME: The new_session_cb is known broken for clients in OpenSSL 1.1.0h.
143
140
# See https://github.com/openssl/openssl/pull/5967 for details.
144
141
skip if OpenSSL ::OPENSSL_LIBRARY_VERSION =~ /OpenSSL 1.1.0h/
145
142
146
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
143
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
147
144
http . use_ssl = true
148
145
http . cert_store = TEST_STORE
149
146
@@ -166,15 +163,13 @@ def test_session_reuse
166
163
assert_equal true , socket . session_reused?
167
164
168
165
http . finish
169
- rescue SystemCallError
170
- skip $!
171
166
end
172
167
173
168
def test_session_reuse_but_expire
174
169
# FIXME: The new_session_cb is known broken for clients in OpenSSL 1.1.0h.
175
170
skip if OpenSSL ::OPENSSL_LIBRARY_VERSION =~ /OpenSSL 1.1.0h/
176
171
177
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
172
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
178
173
http . use_ssl = true
179
174
http . cert_store = TEST_STORE
180
175
@@ -190,8 +185,6 @@ def test_session_reuse_but_expire
190
185
assert_equal false , socket . session_reused?
191
186
192
187
http . finish
193
- rescue SystemCallError
194
- skip $!
195
188
end
196
189
197
190
if ENV [ "RUBY_OPENSSL_TEST_ALL" ]
@@ -206,14 +199,12 @@ def test_verify
206
199
end
207
200
208
201
def test_verify_none
209
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
202
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
210
203
http . use_ssl = true
211
204
http . verify_mode = OpenSSL ::SSL ::VERIFY_NONE
212
205
http . request_get ( "/" ) { |res |
213
206
assert_equal ( $test_net_http_data, res . body )
214
207
}
215
- rescue SystemCallError
216
- skip $!
217
208
end
218
209
219
210
def test_skip_hostname_verification
@@ -242,14 +233,10 @@ def test_fail_if_verify_hostname_is_true
242
233
end
243
234
244
235
def test_certificate_verify_failure
245
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
236
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
246
237
http . use_ssl = true
247
238
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 | }
253
240
}
254
241
assert_match ( /certificate verify failed/ , ex . message )
255
242
unless /mswin|mingw/ =~ RUBY_PLATFORM
@@ -279,10 +266,10 @@ def test_timeout_during_SSL_handshake
279
266
bug4246 = "expected the SSL connection to have timed out but have not. [ruby-core:34203]"
280
267
281
268
# listen for connections... but deliberately do not complete SSL handshake
282
- TCPServer . open ( 'localhost' , 0 ) { |server |
269
+ TCPServer . open ( HOST , 0 ) { |server |
283
270
port = server . addr [ 1 ]
284
271
285
- conn = Net ::HTTP . new ( 'localhost' , port )
272
+ conn = Net ::HTTP . new ( HOST , port )
286
273
conn . use_ssl = true
287
274
conn . read_timeout = 0.01
288
275
conn . open_timeout = 0.01
@@ -297,7 +284,7 @@ def test_timeout_during_SSL_handshake
297
284
end
298
285
299
286
def test_min_version
300
- http = Net ::HTTP . new ( "localhost" , config ( "port" ) )
287
+ http = Net ::HTTP . new ( HOST , config ( "port" ) )
301
288
http . use_ssl = true
302
289
http . min_version = :TLS1
303
290
http . cert_store = TEST_STORE
0 commit comments