Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssl: refactor check_supported_protocol_versions #866

Merged
merged 1 commit into from
Feb 27, 2025
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
40 changes: 18 additions & 22 deletions test/openssl/test_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1243,32 +1243,28 @@ def check_supported_protocol_versions
OpenSSL::SSL::TLS1_1_VERSION,
OpenSSL::SSL::TLS1_2_VERSION,
OpenSSL::SSL::TLS1_3_VERSION,
].compact
]

# Prepare for testing & do sanity check
supported = []
possible_versions.each do |ver|
catch(:unsupported) {
ctx_proc = proc { |ctx|
begin
ctx.min_version = ctx.max_version = ver
rescue ArgumentError, OpenSSL::SSL::SSLError
throw :unsupported
end
ctx_proc = proc { |ctx|
# Explicitly reset them to avoid influenced by OPENSSL_CONF
ctx.min_version = ctx.max_version = nil
}
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
possible_versions.each do |ver|
ctx = OpenSSL::SSL::SSLContext.new
ctx.min_version = ctx.max_version = ver
server_connect(port, ctx) { |ssl|
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
}
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
begin
server_connect(port) { |ssl|
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
}
rescue OpenSSL::SSL::SSLError, Errno::ECONNRESET
else
supported << ver
end
end
}
supported << ver
rescue OpenSSL::SSL::SSLError, Errno::ECONNRESET
end
end
assert_not_empty supported

# Sanity check: in our test suite we assume these are always supported
assert_include(supported, OpenSSL::SSL::TLS1_2_VERSION)
assert_include(supported, OpenSSL::SSL::TLS1_3_VERSION)

supported
end
Expand Down
Loading