883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
40 lines
2.0 KiB
Python
40 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Reject corrupt recovery payloads; uses disposable files, no client or UI."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
import tempfile
|
|
from unittest import mock
|
|
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
import development_client_build as build
|
|
|
|
def refused(directory):
|
|
try:build.verify(directory)
|
|
except ValueError:return
|
|
raise AssertionError('Corrupt/incomplete recovery build accepted')
|
|
|
|
with tempfile.TemporaryDirectory()as temporary:
|
|
root=Path(temporary);(root/'client').mkdir();payload=root/'client/asset.bin'
|
|
payload.write_bytes(b'known client asset')
|
|
row=dict(path='client/asset.bin',bytes=payload.stat().st_size,sha256=hashlib.sha256(payload.read_bytes()).hexdigest())
|
|
manifest=dict(kind='private-forever-development-build',status='COMPLETE',installation={'version':'fixture'},files=[row])
|
|
def publish(value):(root/'manifest.json').write_text(json.dumps(value))
|
|
publish(manifest)
|
|
with mock.patch.object(build,'inspect_installation',return_value=manifest['installation']):
|
|
assert build.verify(root)['verified_files']==1
|
|
payload.write_bytes(b'corrupt same bytes')
|
|
assert payload.stat().st_size==row['bytes'];refused(root)
|
|
payload.write_bytes(b'known client asset')
|
|
publish(dict(manifest,status='COPYING'));refused(root)
|
|
for path in('/absolute.bin','../outside.bin'):
|
|
publish(dict(manifest,files=[dict(row,path=path)]));refused(root)
|
|
publish(manifest);payload.unlink();refused(root)
|
|
outside=root/'outside.bin';outside.write_bytes(b'known client asset');payload.symlink_to(outside)
|
|
refused(root)
|
|
try:build.inventory([root/'client'])
|
|
except ValueError:pass
|
|
else:raise AssertionError('Nested external link accepted')
|
|
print('PASS: recovery verification rejects same-size corruption, incomplete state, escaping paths, missing files and linked payloads; no real build/client modified.')
|