Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions test/openssl/test_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1080,36 +1080,46 @@ def test_tlsext_hostname
end
end

def test_servername_cb_raises_an_exception_on_unknown_objects
hostname = 'example.org'

ctx2 = OpenSSL::SSL::SSLContext.new
ctx2.cert = @svr_cert
ctx2.key = @svr_key
ctx2.servername_cb = lambda { |args| Object.new }

def test_servername_cb_exception
sock1, sock2 = socketpair

t = Thread.new {
s1 = OpenSSL::SSL::SSLSocket.new(sock1)
s1.hostname = "localhost"
assert_raise_with_message(OpenSSL::SSL::SSLError, /unrecognized.name/i) {
s1.connect
}
}

ctx2 = OpenSSL::SSL::SSLContext.new
ctx2.servername_cb = lambda { |args| raise RuntimeError, "foo" }
s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2)
assert_raise_with_message(RuntimeError, "foo") { s2.accept }
assert t.join
ensure
sock1.close
sock2.close
t.kill.join
end

ctx1 = OpenSSL::SSL::SSLContext.new
def test_servername_cb_raises_an_exception_on_unknown_objects
sock1, sock2 = socketpair

s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1)
s1.hostname = hostname
t = Thread.new {
assert_raise(OpenSSL::SSL::SSLError) do
s1.connect
end
s1 = OpenSSL::SSL::SSLSocket.new(sock1)
s1.hostname = "localhost"
assert_raise(OpenSSL::SSL::SSLError) { s1.connect }
}

assert_raise(ArgumentError) do
s2.accept
end

ctx2 = OpenSSL::SSL::SSLContext.new
ctx2.servername_cb = lambda { |args| Object.new }
s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2)
assert_raise(ArgumentError) { s2.accept }
assert t.join
ensure
sock1.close if sock1
sock2.close if sock2
sock1.close
sock2.close
t.kill.join
end

def test_accept_errors_include_peeraddr
Expand Down