"""Fault injection against a real extracted runtime; never modifies the source.""" import argparse import importlib.util from pathlib import Path import shutil import subprocess import tempfile spec = importlib.util.spec_from_file_location('release_check', Path(__file__).with_name('check_macos_release.py')) check = importlib.util.module_from_spec(spec) spec.loader.exec_module(check) def rejected(root, expected): try: check.audit(root) except RuntimeError as error: if expected not in str(error): raise print(f'Correctly rejected: {expected}') else: raise AssertionError(f'Did not reject: {expected}') def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--runtime', type=Path, required=True) args = parser.parse_args() with tempfile.TemporaryDirectory(prefix='cutdex-audit-faults-') as temporary: root = Path(temporary) / 'runtime' shutil.copytree(args.runtime, root, symlinks=True) worker = root / 'workers/asr/cutdex-asr-worker' held = worker.with_suffix('.held') worker.rename(held) rejected(root, 'Missing executable') held.rename(worker) # Use the actual package's version instead of pinning FFmpeg's ABI. library = next((root / 'lib').glob('libavcodec.*.dylib')) saved = Path(temporary) / library.name library.rename(saved) rejected(root, 'Unresolved bundled dependency') saved.rename(library) link = root / 'external-library' link.symlink_to('/usr/lib') rejected(root, 'Symlink escapes bundle') link.unlink() backup = Path(temporary) / 'asr-backup' shutil.copy2(worker, backup) subprocess.run(['/usr/bin/install_name_tool', '-add_rpath', '/tmp/developer-libraries', str(worker)], check=True) rejected(root, 'External runtime search path') shutil.copy2(backup, worker) print(check.audit(root)) if __name__ == '__main__': main()