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

🥅 Re-raise #starttls error from receiver thread #395

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1239,13 +1239,21 @@ def logout!
#
def starttls(**options)
@ssl_ctx_params, @ssl_ctx = build_ssl_ctx(options)
send_command("STARTTLS") do |resp|
error = nil
ok = send_command("STARTTLS") do |resp|
if resp.kind_of?(TaggedResponse) && resp.name == "OK"
clear_cached_capabilities
clear_responses
start_tls_session
end
rescue Exception => error
raise # note that the error backtrace is in the receiver_thread
end
if error
disconnect
raise error
end
ok
end

# :call-seq:
Expand Down
13 changes: 6 additions & 7 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,16 @@ def test_starttls_unknown_ca
omit "This test is not working with Windows" if RUBY_PLATFORM =~ /mswin|mingw/

imap = nil
assert_raise(OpenSSL::SSL::SSLError) do
ex = nil
starttls_test do |port|
imap = Net::IMAP.new("localhost", port: port)
ex = nil
starttls_test do |port|
imap = Net::IMAP.new("localhost", port: port)
begin
imap.starttls
imap
rescue => ex
imap
end
raise ex if ex
imap
end
assert_kind_of(OpenSSL::SSL::SSLError, ex)
assert_equal false, imap.tls_verified?
assert_equal({}, imap.ssl_ctx_params)
assert_equal(nil, imap.ssl_ctx.ca_file)
Expand Down