Skip to content

Commit e2d59c4

Browse files
committed
test: cover Lampstand evidence envelopes
1 parent 11a209d commit e2d59c4

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/test_evidence.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from __future__ import annotations
2+
3+
import copy
4+
import json
5+
6+
from sourceos_syncd.evidence import digest_json, make_evidence, validate_evidence, write_evidence_file
7+
8+
9+
def test_evidence_wraps_artifact_with_digest():
10+
artifact = {
11+
"schema": "sourceos.state-integrity-report/v1alpha1",
12+
"identity": {"component": "sourceos-syncd"},
13+
}
14+
envelope = make_evidence(artifact, "state-integrity-report", "sourceos-syncd")
15+
assert envelope["schema"] == "sourceos.lampstand-evidence/v1alpha1"
16+
assert envelope["artifact_digest"] == digest_json(artifact)
17+
assert envelope["attestation"]["signed"] is False
18+
assert validate_evidence(envelope) == []
19+
20+
21+
def test_evidence_validation_detects_tampering():
22+
artifact = {"schema": "sourceos.policy-decision/v1alpha1", "status": "allowed"}
23+
envelope = make_evidence(artifact, "policy-decision", "sourceos-syncd")
24+
tampered = copy.deepcopy(envelope)
25+
tampered["artifact"]["status"] = "denied"
26+
errors = validate_evidence(tampered)
27+
assert any("artifact_digest does not match artifact" in error for error in errors)
28+
29+
30+
def test_evidence_file_writer_is_valid_json(tmp_path):
31+
artifact = {"schema": "sourceos.repair-plan/v1alpha1", "status": "preview"}
32+
envelope = make_evidence(artifact, "repair-plan", "sourceos-syncd")
33+
path = write_evidence_file(envelope, tmp_path)
34+
assert path.exists()
35+
loaded = json.loads(path.read_text(encoding="utf-8"))
36+
assert loaded["evidence_id"] == envelope["evidence_id"]
37+
assert validate_evidence(loaded) == []

0 commit comments

Comments
 (0)