From 08db305e5af4736c731746953fa68c8acf216b29 Mon Sep 17 00:00:00 2001 From: Sean Whalen <44679+seanthegeek@users.noreply.github.com> Date: Sun, 24 May 2026 14:12:24 -0400 Subject: [PATCH] test: cover no-display-name Reply-To header flattening (#786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 10.0.3 Reply-To header flattening (elastic.py / opensearch.py line 711) has two branches: display-name present ("Name ") and absent (bare address). The existing test only exercised the former, leaving the empty-display-name branch uncovered — the two lines Codecov flagged on the 10.0.3 patch. Add a failure report whose Reply-To has no display name and assert sample.headers["reply-to"] flattens to the bare address. Co-authored-by: Claude Opus 4.7 (1M context) --- tests/test_elastic.py | 17 +++++++++++++++++ tests/test_opensearch.py | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tests/test_elastic.py b/tests/test_elastic.py index a381679..9e54a0d 100644 --- a/tests/test_elastic.py +++ b/tests/test_elastic.py @@ -781,6 +781,23 @@ class TestSaveFailureReport(unittest.TestCase): [a.address for a in doc.sample.reply_to], ["real@phish.example"] ) + def test_reply_to_header_without_display_name_flattens_to_address(self): + """A Reply-To header with no display name flattens to the bare + address — the empty-display branch of the header flattening, + matching the From/To handling.""" + report = _failure_report() + report["parsed_sample"]["headers"]["Reply-To"] = [["", "noname@phish.example"]] + with ( + patch("parsedmarc.elastic.Search", return_value=_empty_search()), + patch("parsedmarc.elastic.Index"), + patch.object( + elastic_module._FailureReportDoc, "save", autospec=True + ) as mock_save, + ): + save_failure_report_to_elasticsearch(report) + doc = mock_save.call_args.args[0] + self.assertEqual(doc.sample.headers["reply-to"], "noname@phish.example") + # --------------------------------------------------------------------------- # save_smtp_tls_report_to_elasticsearch diff --git a/tests/test_opensearch.py b/tests/test_opensearch.py index c610ff8..b0de70b 100644 --- a/tests/test_opensearch.py +++ b/tests/test_opensearch.py @@ -779,6 +779,23 @@ class TestSaveFailureReport(unittest.TestCase): [a.address for a in doc.sample.reply_to], ["real@phish.example"] ) + def test_reply_to_header_without_display_name_flattens_to_address(self): + """A Reply-To header with no display name flattens to the bare + address — the empty-display branch of the header flattening, + matching the From/To handling.""" + report = _failure_report() + report["parsed_sample"]["headers"]["Reply-To"] = [["", "noname@phish.example"]] + with ( + patch("parsedmarc.opensearch.Search", return_value=_empty_search()), + patch("parsedmarc.opensearch.Index"), + patch.object( + opensearch_module._FailureReportDoc, "save", autospec=True + ) as mock_save, + ): + save_failure_report_to_opensearch(report) + doc = mock_save.call_args.args[0] + self.assertEqual(doc.sample.headers["reply-to"], "noname@phish.example") + # --------------------------------------------------------------------------- # save_smtp_tls_report_to_opensearch