security: harden Campaign delivery effects and reconciliation
This commit is contained in:
@@ -3,8 +3,14 @@ from __future__ import annotations
|
||||
from datetime import UTC, datetime
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from govoplan_campaign.backend.reports.campaigns import _job_evidence_row, _latest_by_job_id
|
||||
from govoplan_campaign.backend.reports.campaigns import (
|
||||
_job_evidence_row,
|
||||
_latest_by_job_id,
|
||||
_load_delivery_info,
|
||||
generate_campaign_report,
|
||||
)
|
||||
|
||||
|
||||
def _dt() -> datetime:
|
||||
@@ -87,9 +93,12 @@ def test_job_evidence_row_contains_transport_and_message_evidence() -> None:
|
||||
assert "bundle.zip" in row["attachment_names"]
|
||||
assert "notice.pdf" in row["attachment_names"]
|
||||
assert row["latest_smtp_status_code"] == 250
|
||||
assert row["latest_smtp_response"] == "2.0.0 queued"
|
||||
assert "latest_smtp_response" not in row
|
||||
assert "latest_smtp_error_type" not in row
|
||||
assert "latest_smtp_error_message" not in row
|
||||
assert row["latest_imap_status"] == "appended"
|
||||
assert row["latest_imap_folder"] == "Sent"
|
||||
assert "latest_imap_error_message" not in row
|
||||
assert "eml_storage_key" not in row
|
||||
assert "eml_local_path" not in row
|
||||
|
||||
@@ -107,6 +116,45 @@ def test_latest_by_job_id_keeps_highest_attempt_number() -> None:
|
||||
assert latest["job-2"].attempt_number == 2
|
||||
|
||||
|
||||
def test_invalid_legacy_snapshot_never_echoes_validation_details() -> None:
|
||||
version = SimpleNamespace(
|
||||
execution_snapshot={
|
||||
"snapshot_version": "legacy",
|
||||
"smtp": {"host": "smtp.internal.example", "password": "provider-secret"},
|
||||
},
|
||||
execution_snapshot_hash=None,
|
||||
execution_snapshot_at=None,
|
||||
)
|
||||
|
||||
delivery = _load_delivery_info(version, [])
|
||||
|
||||
assert delivery["load_error"] == "Execution snapshot is invalid; rebuild the selected version before delivery."
|
||||
assert "provider-secret" not in repr(delivery)
|
||||
assert "smtp.internal.example" not in repr(delivery)
|
||||
|
||||
|
||||
def test_aggregate_report_omits_recipient_level_failures_by_default() -> None:
|
||||
campaign = SimpleNamespace(id="campaign-1")
|
||||
version = SimpleNamespace(id="version-1")
|
||||
with (
|
||||
patch("govoplan_campaign.backend.reports.campaigns._get_campaign", return_value=campaign),
|
||||
patch("govoplan_campaign.backend.reports.campaigns._selected_version", return_value=version),
|
||||
patch("govoplan_campaign.backend.reports.campaigns._report_jobs", return_value=[]),
|
||||
patch(
|
||||
"govoplan_campaign.backend.reports.campaigns._campaign_report_payload",
|
||||
return_value={"cards": {}},
|
||||
) as payload,
|
||||
):
|
||||
report = generate_campaign_report(
|
||||
object(), # type: ignore[arg-type]
|
||||
tenant_id="tenant-1",
|
||||
campaign_id="campaign-1",
|
||||
)
|
||||
|
||||
assert report == {"cards": {}}
|
||||
assert payload.call_args.kwargs["include_recent_failures"] is False
|
||||
|
||||
|
||||
class CampaignReportProjectionTests(unittest.TestCase):
|
||||
def test_evidence_projection(self) -> None:
|
||||
test_job_evidence_row_contains_transport_and_message_evidence()
|
||||
|
||||
Reference in New Issue
Block a user