Initial commit

This commit is contained in:
2026-05-16 12:05:36 -03:00
parent 0ce972a361
commit e82cee97a7
65 changed files with 9051 additions and 5 deletions
+44
View File
@@ -0,0 +1,44 @@
from pathlib import Path
import pytest
from app.dmarc_parser import DMARCParseError, parse_dmarc_xml
def test_parser_valid_dmarc_report():
payload = Path("tests/fixtures/sample_dmarc.xml").read_bytes()
report = parse_dmarc_xml(payload)
assert report.org_name == "google.com"
assert report.domain == "tukutoi.com"
assert report.policy_p == "none"
assert report.date_begin is not None
assert len(report.records) == 1
record = report.records[0]
assert record.source_ip == "203.0.113.10"
assert record.count == 25
assert record.dkim_aligned is False
assert record.spf_aligned is False
assert record.dmarc_pass is False
assert {auth.auth_type for auth in record.auth_results} == {"dkim", "spf"}
def test_parser_rejects_record_limit():
payload = Path("tests/fixtures/sample_dmarc.xml").read_bytes()
with pytest.raises(DMARCParseError, match="record limit"):
parse_dmarc_xml(payload, max_records=0)
def test_parser_rejects_invalid_source_ip():
payload = Path("tests/fixtures/sample_dmarc.xml").read_text().replace("203.0.113.10", "not-an-ip").encode()
with pytest.raises(DMARCParseError, match="Invalid source IP"):
parse_dmarc_xml(payload)
def test_parser_rejects_absurd_record_count():
payload = Path("tests/fixtures/sample_dmarc.xml").read_text().replace("<count>25</count>", "<count>10000001</count>").encode()
with pytest.raises(DMARCParseError, match="exceeds limit"):
parse_dmarc_xml(payload, max_record_count=10000000)