Skip to content

Commit 22ed31d

Browse files
committed
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.
1 parent 2f31605 commit 22ed31d

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

test/openssl/test_ssl.rb

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ def test_renegotiation_cb
15291529
num_handshakes = 0
15301530
renegotiation_cb = Proc.new { |ssl| num_handshakes += 1 }
15311531
ctx_proc = Proc.new { |ctx| ctx.renegotiation_cb = renegotiation_cb }
1532-
start_server_version(:SSLv23, ctx_proc) { |port|
1532+
start_server(ctx_proc: ctx_proc) { |port|
15331533
server_connect(port) { |ssl|
15341534
assert_equal(1, num_handshakes)
15351535
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
@@ -1545,7 +1545,7 @@ def test_alpn_protocol_selection_ary
15451545
}
15461546
ctx.alpn_protocols = advertised
15471547
}
1548-
start_server_version(:SSLv23, ctx_proc) { |port|
1548+
start_server(ctx_proc: ctx_proc) { |port|
15491549
ctx = OpenSSL::SSL::SSLContext.new
15501550
ctx.alpn_protocols = advertised
15511551
server_connect(port, ctx) { |ssl|
@@ -1587,9 +1587,10 @@ def test_npn_protocol_selection_ary
15871587

15881588
advertised = ["http/1.1", "spdy/2"]
15891589
ctx_proc = proc { |ctx| ctx.npn_protocols = advertised }
1590-
start_server_version(:TLSv1_2, ctx_proc) { |port|
1590+
start_server(ctx_proc: ctx_proc) { |port|
15911591
selector = lambda { |which|
15921592
ctx = OpenSSL::SSL::SSLContext.new
1593+
ctx.max_version = :TLS1_2
15931594
ctx.npn_select_cb = -> (protocols) { protocols.send(which) }
15941595
server_connect(port, ctx) { |ssl|
15951596
assert_equal(advertised.send(which), ssl.npn_protocol)
@@ -1609,9 +1610,10 @@ def advertised.each
16091610
yield "spdy/2"
16101611
end
16111612
ctx_proc = Proc.new { |ctx| ctx.npn_protocols = advertised }
1612-
start_server_version(:TLSv1_2, ctx_proc) { |port|
1613+
start_server(ctx_proc: ctx_proc) { |port|
16131614
selector = lambda { |selected, which|
16141615
ctx = OpenSSL::SSL::SSLContext.new
1616+
ctx.max_version = :TLS1_2
16151617
ctx.npn_select_cb = -> (protocols) { protocols.to_a.send(which) }
16161618
server_connect(port, ctx) { |ssl|
16171619
assert_equal(selected, ssl.npn_protocol)
@@ -1626,8 +1628,9 @@ def test_npn_protocol_selection_cancel
16261628
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
16271629

16281630
ctx_proc = Proc.new { |ctx| ctx.npn_protocols = ["http/1.1"] }
1629-
start_server_version(:TLSv1_2, ctx_proc) { |port|
1631+
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
16301632
ctx = OpenSSL::SSL::SSLContext.new
1633+
ctx.max_version = :TLS1_2
16311634
ctx.npn_select_cb = -> (protocols) { raise RuntimeError.new }
16321635
assert_raise(RuntimeError) { server_connect(port, ctx) }
16331636
}
@@ -1648,8 +1651,9 @@ def test_npn_selected_protocol_too_long
16481651
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
16491652

16501653
ctx_proc = Proc.new { |ctx| ctx.npn_protocols = ["http/1.1"] }
1651-
start_server_version(:TLSv1_2, ctx_proc) { |port|
1654+
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
16521655
ctx = OpenSSL::SSL::SSLContext.new
1656+
ctx.max_version = :TLS1_2
16531657
ctx.npn_select_cb = -> (protocols) { "a" * 256 }
16541658
assert_handshake_error { server_connect(port, ctx) }
16551659
}
@@ -2057,20 +2061,6 @@ def test_export_keying_material
20572061

20582062
private
20592063

2060-
def start_server_version(version, ctx_proc = nil,
2061-
server_proc = method(:readwrite_loop), &blk)
2062-
ctx_wrap = Proc.new { |ctx|
2063-
ctx.ssl_version = version
2064-
ctx_proc.call(ctx) if ctx_proc
2065-
}
2066-
start_server(
2067-
ctx_proc: ctx_wrap,
2068-
server_proc: server_proc,
2069-
ignore_listener_error: true,
2070-
&blk
2071-
)
2072-
end
2073-
20742064
def server_connect(port, ctx = nil)
20752065
sock = TCPSocket.new("127.0.0.1", port)
20762066
ssl = ctx ? OpenSSL::SSL::SSLSocket.new(sock, ctx) : OpenSSL::SSL::SSLSocket.new(sock)

0 commit comments

Comments
 (0)