Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [sup.git] 01/03: tests: add thread-view-mode test for attachment filename escaping
Date: Fri, 20 Nov 2026 21:37:58 +1100	[thread overview]
Message-ID: <20261120103758.077082D09E4@bl2.djc.id.au> (raw)
In-Reply-To: <179517107783.237609.3020024330765005481@bl2.djc.id.au>

New commit on branch develop:
https://supmua.dev/git/sup/commit/79a417cab8d18ea80a77dbe949563afcb486e40d.html

commit 79a417cab8d18ea80a77dbe949563afcb486e40d
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Fri Nov 20 20:01:12 2026 +1100

    tests: add thread-view-mode test for attachment filename escaping
---
 Manifest.txt                       |  1 +
 test/dummy_source.rb               |  8 +++++
 test/unit/test_thread_view_mode.rb | 74 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+)

diff --git a/Manifest.txt b/Manifest.txt
index 768c91b5..a523f1c5 100644
--- 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
index 0389db2c..7bd32f6b 100644
--- 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
new file mode 100644
index 00000000..bcc5f9ef
--- /dev/null
+++ 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

  reply	other threads:[~2026-11-20 10:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 10:37 [sup.git] branch develop updated (154ff507 -> ab44ffd7) Dan Callaghan
2026-11-20 10:37 ` Dan Callaghan [this message]
2026-11-20 10:37 ` [sup.git] 02/03: strip out slashes in attachment filenames when saving to dir Dan Callaghan
2026-11-20 10:38 ` [sup.git] 03/03: strip out slashes in attachment filenames for fallback text-view mode Dan Callaghan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120103758.077082D09E4@bl2.djc.id.au \
    --to=dan@bl2.djc.id.au \
    --cc=djc@djc.id.au \
    --cc=sup-commits@supmua.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox