"""Validate retained observations and the validator's failure paths.""" import copy import json from pathlib import Path import unittest import probe class HeaderEvidenceTests(unittest.TestCase): def setUp(self): self.result = json.loads(Path(__file__).with_name("results.json").read_text()) def test_retained_observations(self): self.assertTrue(probe.validate(self.result)) def test_missing_row(self): self.result["observations"].pop() with self.assertRaises(ValueError): probe.validate(self.result) def test_duplicate(self): self.result["observations"][1] = copy.deepcopy(self.result["observations"][0]) with self.assertRaises(ValueError): probe.validate(self.result) def test_fabricated_acceptance(self): self.result["observations"][1]["accepted"] = True with self.assertRaises(ValueError): probe.validate(self.result) def test_wrong_key_identity(self): self.result["observations"][0]["keyIdentity"] = "unrelated" with self.assertRaises(ValueError): probe.validate(self.result) def test_changed_key_hash(self): self.result["observations"][0]["recoveredKeySha256"] = "f" * 64 with self.assertRaises(ValueError): probe.validate(self.result) def test_erased_header_is_not_wrong_password(self): row = next(r for r in self.result["observations"] if r["state"] == "live-after-erase") row["returncode"] = 2 with self.assertRaises(ValueError): probe.validate(self.result) def test_changed_tail(self): self.result["observations"][0]["dataRegionUnchanged"] = False with self.assertRaises(ValueError): probe.validate(self.result) if __name__ == "__main__": unittest.main()