mirror of
https://github.com/domainaware/parsedmarc.git
synced 2026-05-25 21:35:22 +00:00
test: cover no-display-name Reply-To header flattening (#786)
The 10.0.3 Reply-To header flattening (elastic.py / opensearch.py line 711)
has two branches: display-name present ("Name <addr>") 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) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user