File size: 1,010 Bytes
7cfea77 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import json
from sipa_scan_ledger.chain import ScanLedger
from sipa_scan_ledger.record import Finding, ScanRecord
from sipa_scan_ledger.verify import verify
def _populate(path):
log = ScanLedger(path)
log.append(ScanRecord("a.com", "t1", [Finding("high", "No forced HTTPS redirect")]))
log.append(ScanRecord("a.com", "t2", []))
return log
def test_clean_ledger_verifies(tmp_path):
p = tmp_path / "l.jsonl"
_populate(p)
res = verify(p)
assert res.ok
assert res.count == 2
def test_missing_file(tmp_path):
res = verify(tmp_path / "nope.jsonl")
assert not res.ok
def test_altered_entry_is_caught(tmp_path):
p = tmp_path / "l.jsonl"
_populate(p)
lines = p.read_text().splitlines()
tampered = json.loads(lines[0])
tampered["findings"] = [] # quietly erase the finding
lines[0] = json.dumps(tampered)
p.write_text("\n".join(lines) + "\n")
res = verify(p)
assert not res.ok
assert any("altered" in x for x in res.problems)
|