File size: 1,146 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
from sipa_scan_ledger.chain import GENESIS, ScanLedger
from sipa_scan_ledger.record import Finding, ScanRecord


def test_chain_links(tmp_path):
    log = ScanLedger(tmp_path / "l.jsonl")
    e1 = log.append(ScanRecord("a.com", "t1", [Finding("low", "x")]))
    e2 = log.append(ScanRecord("b.com", "t2", []))
    assert e1["prev_hash"] == GENESIS
    assert e2["prev_hash"] == e1["hash"]


def test_reopen_continues_sequence(tmp_path):
    p = tmp_path / "l.jsonl"
    log = ScanLedger(p)
    log.append(ScanRecord("a.com", "t1", []))
    last = log.append(ScanRecord("a.com", "t2", []))

    reopened = ScanLedger(p)
    nxt = reopened.append(ScanRecord("a.com", "t3", []))
    assert nxt["seq"] == 2
    assert nxt["prev_hash"] == last["hash"]


def test_history_for_filters_by_target(tmp_path):
    log = ScanLedger(tmp_path / "l.jsonl")
    log.append(ScanRecord("a.com", "t1", [Finding("low", "x")]))
    log.append(ScanRecord("b.com", "t1", [Finding("high", "y")]))
    log.append(ScanRecord("a.com", "t2", []))

    history = log.history_for("a.com")
    assert len(history) == 2
    assert [r.scanned_at for r in history] == ["t1", "t2"]