Skip to content

Commit 749a1b3

Browse files
committed
Split test class because TCPServer couldn't accept localhost and 127.0.0.1 both
1 parent b38c279 commit 749a1b3

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

test/net/http/test_https.rb

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,6 @@ def test_certificate_verify_failure
242242
assert_match(/certificate verify failed/, ex.message)
243243
end
244244

245-
def test_identity_verify_failure
246-
# the certificate's subject has CN=localhost
247-
http = Net::HTTP.new(HOST_IP, config("port"))
248-
http.use_ssl = true
249-
http.cert_store = TEST_STORE
250-
@log_tester = lambda {|_| }
251-
ex = assert_raise(OpenSSL::SSL::SSLError){
252-
http.request_get("/") {|res| }
253-
}
254-
re_msg = /certificate verify failed|hostname \"#{HOST_IP}\" does not match/
255-
assert_match(re_msg, ex.message)
256-
end
257-
258245
def test_timeout_during_SSL_handshake
259246
bug4246 = "expected the SSL connection to have timed out but have not. [ruby-core:34203]"
260247

@@ -302,3 +289,42 @@ def test_max_version
302289
end
303290

304291
end if defined?(OpenSSL::SSL)
292+
293+
class TestNetHTTPSIdentityVerifyFailure < Test::Unit::TestCase
294+
include TestNetHTTPUtils
295+
296+
def self.read_fixture(key)
297+
File.read(File.expand_path("../fixtures/#{key}", __dir__))
298+
end
299+
300+
HOST = 'localhost'
301+
HOST_IP = '127.0.0.1'
302+
CA_CERT = OpenSSL::X509::Certificate.new(read_fixture("cacert.pem"))
303+
SERVER_KEY = OpenSSL::PKey.read(read_fixture("server.key"))
304+
SERVER_CERT = OpenSSL::X509::Certificate.new(read_fixture("server.crt"))
305+
DHPARAMS = OpenSSL::PKey::DH.new(read_fixture("dhparams.pem"))
306+
TEST_STORE = OpenSSL::X509::Store.new.tap {|s| s.add_cert(CA_CERT) }
307+
308+
CONFIG = {
309+
'host' => HOST_IP,
310+
'proxy_host' => nil,
311+
'proxy_port' => nil,
312+
'ssl_enable' => true,
313+
'ssl_certificate' => SERVER_CERT,
314+
'ssl_private_key' => SERVER_KEY,
315+
'ssl_tmp_dh_callback' => proc { DHPARAMS },
316+
}
317+
318+
def test_identity_verify_failure
319+
# the certificate's subject has CN=localhost
320+
http = Net::HTTP.new(HOST_IP, config("port"))
321+
http.use_ssl = true
322+
http.cert_store = TEST_STORE
323+
@log_tester = lambda {|_| }
324+
ex = assert_raise(OpenSSL::SSL::SSLError){
325+
http.request_get("/") {|res| }
326+
}
327+
re_msg = /certificate verify failed|hostname \"#{HOST_IP}\" does not match/
328+
assert_match(re_msg, ex.message)
329+
end
330+
end if defined?(OpenSSL::SSL)

0 commit comments

Comments
 (0)