address backend security and test suggestions

This commit is contained in:
Christian Krakau-Louis
2026-05-18 16:44:06 +02:00
parent 8f7c41193f
commit b4191e956c
11 changed files with 320 additions and 35 deletions
+28 -1
View File
@@ -64,7 +64,7 @@ class TestDMARCParser:
def test_invalid_xml(self):
"""Test that invalid XML raises a ValueError."""
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="Error parsing DMARC XML"):
DMARCParser.parse_file(b"not xml at all", "report.xml")
def test_parse_xml_report_with_namespace(self):
@@ -102,3 +102,30 @@ class TestDMARCParser:
"""Test that an unsupported file extension raises ValueError."""
with pytest.raises(ValueError, match="Could not extract XML"):
DMARCParser.parse_file(b"some content", "report.pdf")
def test_bad_zip_file_returns_no_xml_content(self):
"""A corrupt ZIP should be handled as no extractable XML content."""
with pytest.raises(ValueError, match="Could not extract XML"):
DMARCParser.parse_file(b"not a zip file", "report.zip")
def test_bad_gzip_file_returns_no_xml_content(self):
"""A corrupt GZIP should be handled as no extractable XML content."""
with pytest.raises(ValueError, match="Could not extract XML"):
DMARCParser.parse_file(b"not a gzip file", "report.gz")
def test_parse_xml_without_report_metadata(self):
"""Missing report_metadata should not crash parsing otherwise valid XML."""
xml = b"""
<feedback>
<policy_published>
<domain>example.com</domain>
<p>none</p>
</policy_published>
</feedback>
"""
result = DMARCParser.parse_file(xml, "report.xml")
assert result["domain"] == "example.com"
assert result["records"] == []
assert result["summary"]["total_count"] == 0