Skip to content

Commit 8c49897

Browse files
authored
Merge pull request #866 from rhenium/ky/ssl-fix-flaky-tests
ssl: refactor check_supported_protocol_versions
2 parents bf96565 + aa7f03e commit 8c49897

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

test/openssl/test_ssl.rb

+18-22
Original file line numberDiff line numberDiff line change
@@ -1244,32 +1244,28 @@ def check_supported_protocol_versions
12441244
OpenSSL::SSL::TLS1_1_VERSION,
12451245
OpenSSL::SSL::TLS1_2_VERSION,
12461246
OpenSSL::SSL::TLS1_3_VERSION,
1247-
].compact
1247+
]
12481248

1249-
# Prepare for testing & do sanity check
12501249
supported = []
1251-
possible_versions.each do |ver|
1252-
catch(:unsupported) {
1253-
ctx_proc = proc { |ctx|
1254-
begin
1255-
ctx.min_version = ctx.max_version = ver
1256-
rescue ArgumentError, OpenSSL::SSL::SSLError
1257-
throw :unsupported
1258-
end
1250+
ctx_proc = proc { |ctx|
1251+
# Explicitly reset them to avoid influenced by OPENSSL_CONF
1252+
ctx.min_version = ctx.max_version = nil
1253+
}
1254+
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
1255+
possible_versions.each do |ver|
1256+
ctx = OpenSSL::SSL::SSLContext.new
1257+
ctx.min_version = ctx.max_version = ver
1258+
server_connect(port, ctx) { |ssl|
1259+
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
12591260
}
1260-
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
1261-
begin
1262-
server_connect(port) { |ssl|
1263-
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
1264-
}
1265-
rescue OpenSSL::SSL::SSLError, Errno::ECONNRESET
1266-
else
1267-
supported << ver
1268-
end
1269-
end
1270-
}
1261+
supported << ver
1262+
rescue OpenSSL::SSL::SSLError, Errno::ECONNRESET
1263+
end
12711264
end
1272-
assert_not_empty supported
1265+
1266+
# Sanity check: in our test suite we assume these are always supported
1267+
assert_include(supported, OpenSSL::SSL::TLS1_2_VERSION)
1268+
assert_include(supported, OpenSSL::SSL::TLS1_3_VERSION)
12731269

12741270
supported
12751271
end

0 commit comments

Comments
 (0)