From 2179cb4cb326e1300051aa5b68f74511b8196af5 Mon Sep 17 00:00:00 2001 From: nick evans Date: Wed, 7 May 2025 11:08:54 -0400 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=85=20Split=20ResponseReader=20test?= =?UTF-8?q?=20for=20limited=20io.gets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TruffleRuby handles `io.gets(CRLF, limit)` differently when the limit cuts in the middle of the terminator. It's helpful behavior, but it's different enough to break the tests. --- test/net/imap/test_response_reader.rb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/test/net/imap/test_response_reader.rb b/test/net/imap/test_response_reader.rb index 5d64c07a..cec6768e 100644 --- a/test/net/imap/test_response_reader.rb +++ b/test/net/imap/test_response_reader.rb @@ -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 From 5550784818c0bd5b3bed85ff92d8f218a7eb068f Mon Sep 17 00:00:00 2001 From: nick evans Date: Wed, 7 May 2025 12:24:17 -0400 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=85=20Split=20UIDFetchDataTest=20test?= =?UTF-8?q?s=20for=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Different parts of these test pass or fail on TruffleRuby or JRuby, so I'm splitting them off into their own tests. --- test/net/imap/test_fetch_data.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/net/imap/test_fetch_data.rb b/test/net/imap/test_fetch_data.rb index 7776f25c..bcbbf50c 100644 --- a/test/net/imap/test_fetch_data.rb +++ b/test/net/imap/test_fetch_data.rb @@ -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 From 66dc1f6347783e61a5fe42a5122e3a552771cb1c Mon Sep 17 00:00:00 2001 From: nick evans Date: Wed, 7 May 2025 13:32:44 -0400 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=85=20Simplify=20two=20DeprecatedClie?= =?UTF-8?q?ntOptions=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These tests weren't even using the correct port for the fake server, so there is reason to start it up at all. Also, we have issues with reliably shutting the server down after an error, for both TruffleRuby and JRuby. --- .../imap/test_deprecated_client_options.rb | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/test/net/imap/test_deprecated_client_options.rb b/test/net/imap/test_deprecated_client_options.rb index e6ac95c8..ceb290dd 100644 --- a/test/net/imap/test_deprecated_client_options.rb +++ b/test/net/imap/test_deprecated_client_options.rb @@ -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