commit 79a417cab8d18ea80a77dbe949563afcb486e40d
parent 154ff507798d88288e3b265049244322833a40bc
Author: Dan Callaghan <djc@djc.id.au>
Date: Fri, 20 Nov 2026 20:01:12 +1100
tests: add thread-view-mode test for attachment filename escaping
Diffstat:
3 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/Manifest.txt b/Manifest.txt
@@ -195,6 +195,7 @@ test/unit/test_locale_fiddler.rb
test/unit/test_maildir.rb
test/unit/test_person.rb
test/unit/test_rmail_message.rb
+test/unit/test_thread_view_mode.rb
test/unit/util/test_query.rb
test/unit/util/test_string.rb
test/unit/util/test_uri.rb
diff --git a/test/dummy_source.rb b/test/dummy_source.rb
@@ -61,6 +61,14 @@ class DummySource < Source
def fallback_date_for_message id
@fallback_date
end
+
+ def poll
+ indexed = Index.instance.enum_for(:each_source_info, self.id).map(&:to_i)
+ @messages.each_with_index do |m, i|
+ next if indexed.include? i
+ yield :add, :info => i, :labels => [], :progress => i / @messages.length
+ end
+ end
end
end
diff --git a/test/unit/test_thread_view_mode.rb b/test/unit/test_thread_view_mode.rb
@@ -0,0 +1,74 @@
+require "dummy_buffer"
+require "dummy_source"
+require "test_helper"
+
+require "sup"
+
+module Redwood
+
+class TestThreadViewMode < Minitest::Test
+ def setup
+ $config = {
+ :indent_spaces => 2,
+ :thread_by_subject => false,
+ }
+ @path = Dir.mktmpdir
+ @out = File.open File::NULL, "w"
+ @inp = File.open File::NULL, "r"
+ @screen = Ncurses.newterm "dumb", @out, @inp
+ BufferManager.init
+ Redwood::start
+ Logger.remove_sink $stderr
+ Index.init File.join(@path, "xapian")
+ Index.load
+ @source = DummySource.new("sup-test://test_thread_view_mode")
+ SourceManager.instance.instance_eval '@sources = {}'
+ SourceManager.instance.add_source @source
+ end
+
+ def teardown
+ ObjectSpace.each_object(Class).select {|a| a < Singleton}.each do |klass|
+ klass.deinstantiate! unless klass == Logger
+ end
+ FileUtils.rm_r @path
+ Ncurses.delscreen @screen
+ @inp.close
+ @out.close
+ $config = nil
+ end
+
+ def populate_threadset
+ PollManager.poll_from @source
+ Index.save_index
+ ts = ThreadSet.new Index.instance
+ Index.instance.each_message { |m| ts.load_thread_for_message m }
+ ts
+ end
+
+ def make_mode thread
+ mode = ThreadViewMode.new thread
+ mode.buffer = DummyBuffer.new 100, 24
+ mode.send :regen_text
+ mode
+ end
+
+ def test_attachment_filenames_escaping
+ @source.messages = [ fixture_path("malicious-attachment-names.eml") ]
+ ts = populate_threadset
+ t = ts.threads.first
+ mode = make_mode t
+ mode.jump_to_message t.first
+
+ ## Test saving all attachments to disk.
+ destdir = File.join(@path, "saved")
+ Dir.mkdir destdir
+ stub(BufferManager.instance).ask(:filename, "Save all attachments to folder: ", "") { destdir }
+ stub(BufferManager.instance).flash("Wrote 1 attachment to #{destdir}.")
+ mode.save_all_to_disk
+ expected_path = File.join destdir, "sup_.travis.yml"
+ assert File.exist? expected_path
+ assert_equal 260, File.size(expected_path)
+ end
+end
+
+end