Add TLS reports capabilities
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app.tlsrpt_parser import TLSRPTParseError, parse_tlsrpt_json
|
||||
|
||||
|
||||
def test_parser_valid_tlsrpt_report():
|
||||
payload = Path("tests/fixtures/sample_tlsrpt.json").read_bytes()
|
||||
report = parse_tlsrpt_json(payload)
|
||||
|
||||
assert report.org_name == "Google Inc."
|
||||
assert report.domain == "anamaka.net"
|
||||
assert report.report_id == "2026-06-17T00:00:00Z_anamaka.net"
|
||||
assert report.date_begin is not None
|
||||
assert len(report.policies) == 1
|
||||
policy = report.policies[0]
|
||||
assert policy.policy_type == "sts"
|
||||
assert policy.policy_domain == "anamaka.net"
|
||||
assert policy.mx_hosts == ["mail.dynamicpress.org"]
|
||||
assert policy.total_successful_session_count == 5
|
||||
assert policy.total_failure_session_count == 0
|
||||
|
||||
|
||||
def test_parser_rejects_missing_policy_domain():
|
||||
payload = Path("tests/fixtures/sample_tlsrpt.json").read_text().replace('"policy-domain": "anamaka.net"', '"policy-domain": ""').encode()
|
||||
|
||||
with pytest.raises(TLSRPTParseError, match="Missing TLS policy domain"):
|
||||
parse_tlsrpt_json(payload)
|
||||
|
||||
|
||||
def test_parser_rejects_negative_session_count():
|
||||
payload = Path("tests/fixtures/sample_tlsrpt.json").read_text().replace('"total-failure-session-count": 0', '"total-failure-session-count": -1').encode()
|
||||
|
||||
with pytest.raises(TLSRPTParseError, match="must not be negative"):
|
||||
parse_tlsrpt_json(payload)
|
||||
Reference in New Issue
Block a user