websecure / hackathon-techex /tests /test_diff.py
SoulInPsyAbstract's picture
Mirror GitHub commit 954b20931bd23bf971072a5ec79424ac03b09d6b (committed 2026-09-12T11:35:28+03:00), pushed 2026-09-12T08:35:36Z
7cfea77 verified
Raw
History Blame Contribute Delete
1.31 kB
import pytest
from sipa_scan_ledger.diff import diff_scans
from sipa_scan_ledger.record import Finding, ScanRecord
def test_new_finding_detected():
before = ScanRecord("a.com", "t1", [Finding("low", "Missing HSTS")])
after = ScanRecord("a.com", "t2", [Finding("low", "Missing HSTS"), Finding("high", "No forced HTTPS redirect")])
d = diff_scans(before, after)
assert len(d.new_findings) == 1
assert d.new_findings[0]["title"] == "No forced HTTPS redirect"
assert d.got_worse()
def test_resolved_finding_detected():
before = ScanRecord("a.com", "t1", [Finding("high", "No forced HTTPS redirect")])
after = ScanRecord("a.com", "t2", [])
d = diff_scans(before, after)
assert len(d.resolved_findings) == 1
assert d.improved()
assert not d.got_worse()
def test_unchanged_findings_tracked():
before = ScanRecord("a.com", "t1", [Finding("low", "Missing HSTS")])
after = ScanRecord("a.com", "t2", [Finding("low", "Missing HSTS")])
d = diff_scans(before, after)
assert len(d.unchanged_findings) == 1
assert not d.new_findings and not d.resolved_findings
def test_different_targets_raises():
before = ScanRecord("a.com", "t1", [])
after = ScanRecord("b.com", "t2", [])
with pytest.raises(ValueError):
diff_scans(before, after)