Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/net/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ def do_start(helo_domain, user, secret, authtype)
if user || secret || authtype
check_auth_args authtype, user, secret
end
@error_occurred = false
s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
tcp_socket(@address, @port)
end
Expand Down
26 changes: 26 additions & 0 deletions test/net/smtp/test_smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,32 @@ def test_start_instance
smtp.finish
end

def test_start_instance_after_failed_greeting
smtp = Net::SMTP.new("example.invalid", starttls: false)
socket = Object.new
socket.define_singleton_method(:close) {}
smtp.define_singleton_method(:tcp_socket) { |*| socket }
smtp.define_singleton_method(:new_internet_message_io) { |io| io }
greetings = 0
smtp.define_singleton_method(:recv_response) do
greetings += 1
raise EOFError if greetings == 1
Net::SMTP::Response.parse("220 ready")
end
smtp.define_singleton_method(:do_helo) { |_| }
smtp.define_singleton_method(:do_finish) do
@started = false
@socket = nil
end

assert_raise(EOFError) { smtp.start }
smtp.start
assert_equal 2, greetings
assert smtp.started?
ensure
smtp.finish if smtp&.started?
end

def test_start_instance_with_position_argument
port = fake_server_start(auth: 'plain')
smtp = Net::SMTP.new('localhost', port)
Expand Down