okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
477fd36bc
main
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 ): 21def test_the_release_feed_key_is_shipped_and_valid (self ): 22with mock .patch .dict (os .environ , {signing .ENV_EXTRA_KEYS :"" }): 23keys = signing .load_trusted_keys () 24self .assertEqual (list (keys ), [RELEASE_KEY_ID ])# only the release key: no tester or local-test key in a release build 25self .assertEqual (signing .key_id_of (keys [RELEASE_KEY_ID ]),RELEASE_KEY_ID ) 26 27def test_the_app_key_is_the_one_in_the_tauri_config (self ): 28shipped = json .loads ((ROOT / "strata_control" / "update_keys.json" ).read_text (encoding = "utf-8-sig" ))["app_minisign_public" ] 29conf = json .loads (TAURI_CONF .read_text (encoding = "utf-8-sig" ))["plugins" ]["updater" ]["pubkey" ] 30self .assertEqual (shipped ,conf ) 31key_id ,public = signing .minisign_public (shipped )# parses as a real Ed25519 minisign key, not the placeholder 32self .assertEqual (len (public ),32 ) 33self .assertEqual (signing .app_public_key if False else shipped ,conf ) 34 35def test_a_feed_signed_by_another_key_is_refused_and_a_tester_key_works_through_the_override (self ): 36other = fx .make_key () 37with tempfile .TemporaryDirectory ()as t : 38extra = Path (t )/ "tester-keys.json" 39extra .write_text (json .dumps ({"keys" : [signing .public_part (other )]})) 40with mock .patch .dict (os .environ , {signing .ENV_EXTRA_KEYS :"" }): 41self .assertNotIn (other ["key_id" ],signing .load_trusted_keys ())# a tester key is not part of a release build 42with mock .patch .dict (os .environ , {signing .ENV_EXTRA_KEYS :str (extra )}): 43keys = signing .load_trusted_keys () 44self .assertIn (other ["key_id" ],keys )# private tester builds: their key via the override 45self .assertIn (RELEASE_KEY_ID ,keys )# ... beside the release key 46 47 48if __name__ == "__main__" : 49unittest .main ()