Skip to content

✅ Update ResponseReader, UIDFetchData, DeprecatedClientOptions tests #476

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

Merged
merged 3 commits into from
May 8, 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
24 changes: 4 additions & 20 deletions test/net/imap/test_deprecated_client_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,15 @@ class InitializeTests < DeprecatedClientOptionsTest
end

test "combined options hash and keyword args raises ArgumentError" do
ex = nil
run_fake_server_in_thread(
ignore_io_error: true, implicit_tls: true
) do |server|
imap = Net::IMAP.new("localhost", {port: 993}, ssl: true)
rescue => ex
nil
ensure
imap&.disconnect
assert_raise_with_message ArgumentError, /deprecated.*keyword arg/ do
Net::IMAP.new("localhost", {port: 993}, ssl: true)
end
assert_equal ArgumentError, ex.class
end

test "combined options hash and ssl args raises ArgumentError" do
ex = nil
run_fake_server_in_thread(
ignore_io_error: true, implicit_tls: true
) do |server|
imap = Net::IMAP.new("localhost", {port: 993}, true)
rescue => ex
nil
ensure
imap&.disconnect
assert_raise_with_message ArgumentError, /deprecated SSL.*options hash/ do
Net::IMAP.new("localhost", {port: 993}, true)
end
assert_equal ArgumentError, ex.class
end

end
Expand Down
20 changes: 12 additions & 8 deletions test/net/imap/test_fetch_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ def fetch_data_class
assert_equal 22222, data.uid
end

test "#uid warns when differs from UID attribute" do
data = nil
test "#initialize warns when uid differs from attr['UID']" do
assert_warn(/UIDs do not match/i) do
data = Net::IMAP::UIDFetchData.new(22222, "UID" => 54_321)
Net::IMAP::UIDFetchData.new(22222, "UID" => 54_321)
end
end

test "#uid ignores the UID attribute" do
data = EnvUtil.suppress_warning {
Net::IMAP::UIDFetchData.new(22222, "UID" => 54_321)
}
assert_equal 22222, data.uid
end

test "#deconstruct_keys" do
assert_warn(/UIDs do not match/i) do
Net::IMAP::UIDFetchData.new(22222, "UID" => 54_321) => {
uid: 22222
}
end
data = EnvUtil.suppress_warning {
Net::IMAP::UIDFetchData.new(22222, "UID" => 54_321)
}
assert_pattern { data => { uid: 22222 } }
end
end

Expand Down
26 changes: 23 additions & 3 deletions test/net/imap/test_response_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,33 @@ def literal(str) = "{#{str.bytesize}}\r\n#{str}"
client.config.max_response_size = 10
under = "+ 3456\r\n"
exact = "+ 345678\r\n"
over = "+ 3456789\r\n"
io = StringIO.new([under, exact, over].join)
very_over = "+ 3456789 #{?a * (16<<10)}}\r\n"
slightly_over = "+ 34567890\r\n" # CRLF after the limit
io = StringIO.new([under, exact, very_over, slightly_over].join)
rcvr = Net::IMAP::ResponseReader.new(client, io)
assert_equal under, rcvr.read_response_buffer.to_str
assert_equal exact, rcvr.read_response_buffer.to_str
assert_raise Net::IMAP::ResponseTooLargeError do
rcvr.read_response_buffer
result = rcvr.read_response_buffer
flunk "Got result: %p" % [result]
end
io = StringIO.new(slightly_over)
rcvr = Net::IMAP::ResponseReader.new(client, io)
assert_raise Net::IMAP::ResponseTooLargeError do
result = rcvr.read_response_buffer
flunk "Got result: %p" % [result]
end
end

test "#read_response_buffer max_response_size straddling CRLF" do
barely_over = "+ 3456789\r\n" # CRLF straddles the boundary
client = FakeClient.new
client.config.max_response_size = 10
io = StringIO.new(barely_over)
rcvr = Net::IMAP::ResponseReader.new(client, io)
assert_raise Net::IMAP::ResponseTooLargeError do
result = rcvr.read_response_buffer
flunk "Got result: %p" % [result]
end
end

Expand Down
Loading