#!/usr/bin/env python3 """Check an installed native launcher's key-file transport without launching an agent.""" import importlib.util import json import os from pathlib import Path import secrets import subprocess import sys import tempfile from unittest.mock import patch def main(): path = Path(sys.argv[1]).resolve() spec = importlib.util.spec_from_file_location('native_launcher_fixture', path) launcher = importlib.util.module_from_spec(spec) spec.loader.exec_module(launcher) with tempfile.TemporaryDirectory(prefix='strata-launcher-auth-') as directory: root = Path(directory) key = root / 'key with spaces' token = secrets.token_urlsafe(32) key.write_text(token + '\n') key.chmod(0o600) target = {'backend': 'strata-native', 'url': 'http://127.0.0.1:18084', 'key_file': str(key)} launcher.validate_connection(target) assert launcher.connection_key(target) == token key.chmod(0o644) try: launcher.connection_key(target) raise AssertionError('insecure key accepted') except RuntimeError: pass key.chmod(0o600) state = {'backend': 'strata-native', 'model': 'fixture', 'context': 262144, 'parallel': 1} captured = {} class ExecCaptured(BaseException): pass def capture(binary, command, env): captured.update(binary=binary, command=command, env=env) raise ExecCaptured() with patch.object(launcher, 'connection', return_value=target), \ patch.object(launcher, 'discover', return_value=state), \ patch.object(launcher, 'configure', return_value=({'reasoning': 'none'}, 229376, root/'catalog.json')), \ patch.object(launcher.shutil, 'which', return_value='/bin/echo'), \ patch.object(launcher.os, 'execvpe', side_effect=capture), \ patch.object(launcher.sys, 'argv', ['qwen-codex', 'exec', 'fixture']): try: launcher.launch_main() raise AssertionError('native exec not reached') except ExecCaptured: pass serialized = json.dumps(captured) assert token not in serialized, 'key leaked into argv or environment' command = captured['command'] settings = [command[i+1] for i, arg in enumerate(command[:-1]) if arg == '--config'] helper = json.loads(next(s.split('=', 1)[1] for s in settings if s.startswith('model_providers.qwen_native.auth.command='))) args = json.loads(next(s.split('=', 1)[1] for s in settings if s.startswith('model_providers.qwen_native.auth.args='))) assert helper == '/bin/cat' and args == [str(key.resolve())] assert subprocess.check_output([helper, *args], text=True).strip() == token assert not list(root.glob('*.json')), 'intercepted launcher unexpectedly wrote config' print('Installed launcher auth passed: private key validation, token-free argv/environment and exact auth helper output') if __name__ == '__main__': main()