okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-020-release into f-020-int (0.2.0 release wiring and docs)477fd36bc

main
2.6 KiB49 linesraw
1"""The keys shipped with a release build (strata_control/update_keys.json): the release feed key and the Tauri app key are there,
2the tester / local-test keys are not (they come with STRATA_UPDATE_TRUSTED_KEYS), and a feed is verified against them."""
3from __future__ import annotations
4
5import json
6import os
7import tempfile
8import unittest
9from pathlib import Path
10from unittest import mock
11
12from strata_control import feed as feedmod, signing
13from tests.terminal import update_fixture as fx
14
15ROOT = Path(__file__).resolve().parents[2]
16RELEASE_KEY_ID = "5d1bc23abbeffd0d"
17TAURI_CONF = ROOT / "apps" / "desktop" / "src-tauri" / "tauri.conf.json"
18
19
20class ShippedKeys(unittest.TestCase):
21    def test_the_release_feed_key_is_shipped_and_valid(self):
22        with mock.patch.dict(os.environ, {signing.ENV_EXTRA_KEYS: ""}):
23            keys = signing.load_trusted_keys()
24        self.assertEqual(list(keys), [RELEASE_KEY_ID])           # only the release key: no tester or local-test key in a release build
25        self.assertEqual(signing.key_id_of(keys[RELEASE_KEY_ID]), RELEASE_KEY_ID)
26
27    def test_the_app_key_is_the_one_in_the_tauri_config(self):
28        shipped = json.loads((ROOT / "strata_control" / "update_keys.json").read_text(encoding="utf-8-sig"))["app_minisign_public"]
29        conf = json.loads(TAURI_CONF.read_text(encoding="utf-8-sig"))["plugins"]["updater"]["pubkey"]
30        self.assertEqual(shipped, conf)
31        key_id, public = signing.minisign_public(shipped)         # parses as a real Ed25519 minisign key, not the placeholder
32        self.assertEqual(len(public), 32)
33        self.assertEqual(signing.app_public_key if False else shipped, conf)
34
35    def test_a_feed_signed_by_another_key_is_refused_and_a_tester_key_works_through_the_override(self):
36        other = fx.make_key()
37        with tempfile.TemporaryDirectory() as t:
38            extra = Path(t) / "tester-keys.json"
39            extra.write_text(json.dumps({"keys": [signing.public_part(other)]}))
40            with mock.patch.dict(os.environ, {signing.ENV_EXTRA_KEYS: ""}):
41                self.assertNotIn(other["key_id"], signing.load_trusted_keys())          # a tester key is not part of a release build
42            with mock.patch.dict(os.environ, {signing.ENV_EXTRA_KEYS: str(extra)}):
43                keys = signing.load_trusted_keys()
44            self.assertIn(other["key_id"], keys)                                         # private tester builds: their key via the override
45            self.assertIn(RELEASE_KEY_ID, keys)                                          # ... beside the release key
46
47
48if __name__ == "__main__":
49    unittest.main()