@@ -1080,36 +1080,46 @@ def test_tlsext_hostname
10801080 end
10811081 end
10821082
1083- def test_servername_cb_raises_an_exception_on_unknown_objects
1084- hostname = 'example.org'
1085-
1086- ctx2 = OpenSSL ::SSL ::SSLContext . new
1087- ctx2 . cert = @svr_cert
1088- ctx2 . key = @svr_key
1089- ctx2 . servername_cb = lambda { |args | Object . new }
1090-
1083+ def test_servername_cb_exception
10911084 sock1 , sock2 = socketpair
10921085
1086+ t = Thread . new {
1087+ s1 = OpenSSL ::SSL ::SSLSocket . new ( sock1 )
1088+ s1 . hostname = "localhost"
1089+ assert_raise_with_message ( OpenSSL ::SSL ::SSLError , /unrecognized.name/i ) {
1090+ s1 . connect
1091+ }
1092+ }
1093+
1094+ ctx2 = OpenSSL ::SSL ::SSLContext . new
1095+ ctx2 . servername_cb = lambda { |args | raise RuntimeError , "foo" }
10931096 s2 = OpenSSL ::SSL ::SSLSocket . new ( sock2 , ctx2 )
1097+ assert_raise_with_message ( RuntimeError , "foo" ) { s2 . accept }
1098+ assert t . join
1099+ ensure
1100+ sock1 . close
1101+ sock2 . close
1102+ t . kill . join
1103+ end
10941104
1095- ctx1 = OpenSSL ::SSL ::SSLContext . new
1105+ def test_servername_cb_raises_an_exception_on_unknown_objects
1106+ sock1 , sock2 = socketpair
10961107
1097- s1 = OpenSSL ::SSL ::SSLSocket . new ( sock1 , ctx1 )
1098- s1 . hostname = hostname
10991108 t = Thread . new {
1100- assert_raise ( OpenSSL ::SSL ::SSLError ) do
1101- s1 . connect
1102- end
1109+ s1 = OpenSSL ::SSL ::SSLSocket . new ( sock1 )
1110+ s1 . hostname = "localhost"
1111+ assert_raise ( OpenSSL :: SSL :: SSLError ) { s1 . connect }
11031112 }
11041113
1105- assert_raise ( ArgumentError ) do
1106- s2 . accept
1107- end
1108-
1114+ ctx2 = OpenSSL :: SSL :: SSLContext . new
1115+ ctx2 . servername_cb = lambda { | args | Object . new }
1116+ s2 = OpenSSL :: SSL :: SSLSocket . new ( sock2 , ctx2 )
1117+ assert_raise ( ArgumentError ) { s2 . accept }
11091118 assert t . join
11101119 ensure
1111- sock1 . close if sock1
1112- sock2 . close if sock2
1120+ sock1 . close
1121+ sock2 . close
1122+ t . kill . join
11131123 end
11141124
11151125 def test_accept_errors_include_peeraddr
0 commit comments