Files
rust-discovery/tests/apt_transaction/test_signed_helper_envelope.py
T
BuTzZ 6c3203d725
Rust development slice / linux (push) Failing after 1m10s
feat: snapshot Linux-first RMM MVP and pause handover
2026-11-12 22:06:25 +01:00

70 lines
3.7 KiB
Python

"""The provider consumes the exact signed domain job, never a detached manifest."""
import copy
import json
import tempfile
from pathlib import Path
from unittest import TestCase
from unittest.mock import patch
from test_guard import apt
from test_native_acceptance import context, fixture_transaction, action_manifest, signed_job
class SignedHelperEnvelopeTests(TestCase):
def test_pregrant_baselines_are_content_addressed_and_do_not_reset_artifacts(self):
with tempfile.TemporaryDirectory(dir='/tmp/opencode') as temp:
base = Path(temp)
(base / 'baselines').mkdir(mode=0o700)
snapshot = {'rmm-mvp-test:all': {'version': '1.0', 'status': 'install ok installed'}}
with patch.object(apt, 'BASE', base), patch.object(apt.os, 'geteuid', return_value=0), \
patch.object(apt, 'secure_path'), patch.object(apt, 'installed_snapshot', return_value=snapshot), \
patch.object(apt, 'status_fingerprint', return_value='a' * 64), \
patch.object(apt, 'sealed_read', side_effect=lambda path: path.read_bytes()):
result = apt.prepare_baseline_store()
path = base / 'baselines' / (result['baseline_sha256'] + '.json')
self.assertEqual(json.loads(path.read_bytes()), snapshot)
self.assertFalse(result['authorization_created'])
self.assertFalse(result['native_acceptance_created'])
initial = path.stat().st_mtime_ns
self.assertEqual(apt.prepare_baseline_store(), result)
self.assertEqual(path.stat().st_mtime_ns, initial)
snapshot['rmm-mvp-test:all']['version'] = '1.1'
newer = apt.prepare_baseline_store()
self.assertNotEqual(newer['baseline_sha256'], result['baseline_sha256'])
self.assertEqual(len(list((base / 'baselines').iterdir())), 2)
def test_detached_manifest_aliases_wrong_ids_and_nonexact_bytes_are_rejected(self):
obj = fixture_transaction()
tx = apt.ResolvedAptTransaction.parse(obj)
raw_tx = apt.canonical(obj)
ctx = context()
ctx = apt.VerifiedHelperContext(**{**ctx.__dict__, 'transaction_sha256': apt.digest(raw_tx)})
manifest = action_manifest(ctx, obj, {})
valid = signed_job(ctx, manifest)
variants = [manifest]
for fault in ('job-id', 'script-alias', 'transaction-byte', 'transaction-bool', 'schema', 'extra-root'):
changed = copy.deepcopy(valid)
if fault == 'job-id':
changed['job_id'] = 'another-job'
elif fault == 'script-alias':
changed['action']['action'] = 'run_script'
elif fault == 'schema':
changed['action']['apt_manifest']['schema_version'] = 1
elif fault == 'extra-root':
changed['unsigned_manifest'] = manifest
else:
changed['action']['apt_manifest']['transaction_bytes'][0] = True if fault == 'transaction-bool' else 0
variants.append(changed)
for value in variants:
raw = apt.canonical(value)
candidate = apt.VerifiedHelperContext(**{**ctx.__dict__, 'job_payload_sha256': apt.digest(raw)})
def read(path, *args):
return {apt.ACTIVE / 'signed-action.json': raw,
apt.ACTIVE / 'expectation.json': raw_tx,
apt.CODE: b'code', Path(apt.HOOK): apt.hook_script()}[path]
with self.subTest(value=value.get('type', 'job')), patch.object(apt, 'sealed_read', side_effect=read):
with self.assertRaises(apt.Veto):
apt.load_signed_action(tx, candidate)