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
2 changes: 1 addition & 1 deletion lib/net/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ def started?
#
def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil)
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..4)" if args.size > 4
raise IOError, 'SMTP session already started' if @started
helo ||= args[0] || 'localhost'
user ||= args[1]
secret ||= password || args[2]
Expand Down Expand Up @@ -664,7 +665,6 @@ def tcp_socket(address, port)
end

def do_start(helo_domain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
if user || secret || authtype
check_auth_args authtype, user, secret
end
Expand Down
14 changes: 14 additions & 0 deletions test/net/smtp/test_smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,20 @@ def test_start_instance
smtp.finish
end

def test_nested_block_start_preserves_active_session
server = FakeServer.start
smtp = Net::SMTP.start("localhost", server.port)

error = assert_raise(IOError) do
smtp.start { flunk("nested start must not yield") }
end
assert_equal "SMTP session already started", error.message
assert smtp.started?
assert smtp.rset.success?
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