[ruby/openssl] ssl: remove start_server_version from tests
Use start_server instead of start_server_version. start_server_version is a wrapper around start_server that forces the server to a specific protocol version using the now-deprecated method SSLSocket#ssl_version=, but it does more than that. The slightly different method signature and default values are confusing. Let's use start_server directly. https://github.com/ruby/openssl/commit/22ed31d77e
This commit is contained in:
parent
237c71fc29
commit
1f4fc2e608
@ -1529,7 +1529,7 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
|
||||
num_handshakes = 0
|
||||
renegotiation_cb = Proc.new { |ssl| num_handshakes += 1 }
|
||||
ctx_proc = Proc.new { |ctx| ctx.renegotiation_cb = renegotiation_cb }
|
||||
start_server_version(:SSLv23, ctx_proc) { |port|
|
||||
start_server(ctx_proc: ctx_proc) { |port|
|
||||
server_connect(port) { |ssl|
|
||||
assert_equal(1, num_handshakes)
|
||||
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
|
||||
@ -1545,7 +1545,7 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
|
||||
}
|
||||
ctx.alpn_protocols = advertised
|
||||
}
|
||||
start_server_version(:SSLv23, ctx_proc) { |port|
|
||||
start_server(ctx_proc: ctx_proc) { |port|
|
||||
ctx = OpenSSL::SSL::SSLContext.new
|
||||
ctx.alpn_protocols = advertised
|
||||
server_connect(port, ctx) { |ssl|
|
||||
@ -1587,9 +1587,10 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
|
||||
|
||||
advertised = ["http/1.1", "spdy/2"]
|
||||
ctx_proc = proc { |ctx| ctx.npn_protocols = advertised }
|
||||
start_server_version(:TLSv1_2, ctx_proc) { |port|
|
||||
start_server(ctx_proc: ctx_proc) { |port|
|
||||
selector = lambda { |which|
|
||||
ctx = OpenSSL::SSL::SSLContext.new
|
||||
ctx.max_version = :TLS1_2
|
||||
ctx.npn_select_cb = -> (protocols) { protocols.send(which) }
|
||||
server_connect(port, ctx) { |ssl|
|
||||
assert_equal(advertised.send(which), ssl.npn_protocol)
|
||||
@ -1609,9 +1610,10 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
|
||||
yield "spdy/2"
|
||||
end
|
||||
ctx_proc = Proc.new { |ctx| ctx.npn_protocols = advertised }
|
||||
start_server_version(:TLSv1_2, ctx_proc) { |port|
|
||||
start_server(ctx_proc: ctx_proc) { |port|
|
||||
selector = lambda { |selected, which|
|
||||
ctx = OpenSSL::SSL::SSLContext.new
|
||||
ctx.max_version = :TLS1_2
|
||||
ctx.npn_select_cb = -> (protocols) { protocols.to_a.send(which) }
|
||||
server_connect(port, ctx) { |ssl|
|
||||
assert_equal(selected, ssl.npn_protocol)
|
||||
@ -1626,8 +1628,9 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
|
||||
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
|
||||
|
||||
ctx_proc = Proc.new { |ctx| ctx.npn_protocols = ["http/1.1"] }
|
||||
start_server_version(:TLSv1_2, ctx_proc) { |port|
|
||||
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
|
||||
ctx = OpenSSL::SSL::SSLContext.new
|
||||
ctx.max_version = :TLS1_2
|
||||
ctx.npn_select_cb = -> (protocols) { raise RuntimeError.new }
|
||||
assert_raise(RuntimeError) { server_connect(port, ctx) }
|
||||
}
|
||||
@ -1648,8 +1651,9 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
|
||||
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
|
||||
|
||||
ctx_proc = Proc.new { |ctx| ctx.npn_protocols = ["http/1.1"] }
|
||||
start_server_version(:TLSv1_2, ctx_proc) { |port|
|
||||
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
|
||||
ctx = OpenSSL::SSL::SSLContext.new
|
||||
ctx.max_version = :TLS1_2
|
||||
ctx.npn_select_cb = -> (protocols) { "a" * 256 }
|
||||
assert_handshake_error { server_connect(port, ctx) }
|
||||
}
|
||||
@ -2057,20 +2061,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
|
||||
|
||||
private
|
||||
|
||||
def start_server_version(version, ctx_proc = nil,
|
||||
server_proc = method(:readwrite_loop), &blk)
|
||||
ctx_wrap = Proc.new { |ctx|
|
||||
ctx.ssl_version = version
|
||||
ctx_proc.call(ctx) if ctx_proc
|
||||
}
|
||||
start_server(
|
||||
ctx_proc: ctx_wrap,
|
||||
server_proc: server_proc,
|
||||
ignore_listener_error: true,
|
||||
&blk
|
||||
)
|
||||
end
|
||||
|
||||
def server_connect(port, ctx = nil)
|
||||
sock = TCPSocket.new("127.0.0.1", port)
|
||||
ssl = ctx ? OpenSSL::SSL::SSLSocket.new(sock, ctx) : OpenSSL::SSL::SSLSocket.new(sock)
|
||||
|
Loading…
x
Reference in New Issue
Block a user