#!/usr/bin/env python3 """Run the installer's actual proxy verification with deterministic HTTP transports.""" import os from pathlib import Path import subprocess import tempfile source = Path(__file__).resolve().parent.parent with tempfile.TemporaryDirectory(prefix='easyai-proxy-entry-') as temporary: root = Path(temporary) script = (source / 'start.sh').read_text().rsplit('main "$@"', 1)[0] (root / 'functions.sh').write_text(script) curl = root / 'curl' curl.write_text('''#!/usr/bin/env python3 import json,os,sys with open(os.environ['CURL_CALLS'],'a') as out:out.write(json.dumps(sys.argv[1:])+'\\n') if os.environ['HTTP_CASE']=='home-error':sys.exit(22) if any('/api/health/update-ready' in arg for arg in sys.argv): if os.environ['HTTP_CASE']=='delayed-reload' and open(os.environ['CURL_CALLS']).read().count('/api/health/update-ready')==1: print('redirect\\n301');sys.exit(0) print(json.dumps({'status':'ok','service':'wrong-upstream' if os.environ['HTTP_CASE']=='wrong-upstream' else 'easyai-server-main'})+'\\n200') else: print('200',end='') ''') curl.chmod(0o755) for name, mode, succeeds in [('home-error', 'ip', False), ('wrong-upstream', 'domain', False), ('healthy', 'ip', True), ('healthy', 'https', True), ('delayed-reload', 'domain', True)]: log = root / 'curl.jsonl' log.write_text('') env = {**os.environ, 'PATH': str(root) + os.pathsep + os.environ['PATH'], 'HTTP_CASE': name, 'CURL_CALLS': str(log), 'DEPLOY_PROXY_TIMEOUT_SECONDS':'8' if succeeds else '1'} run = '. ./functions.sh; DEPLOY_MODE="$1"; DEPLOY_IP=192.0.2.10; DEPLOY_DOMAIN=deployment.example; DEPLOY_HTTPS=false; if [ "$1" = https ]; then DEPLOY_MODE=domain; DEPLOY_HTTPS=true; fi; verify_proxy_entry' result = subprocess.run(['bash', '-c', run, 'fixture', mode], cwd=root, env=env, capture_output=True, text=True, timeout=15) assert (result.returncode == 0) == succeeds, (name, mode, result.stdout, result.stderr) calls = log.read_text() if mode == 'ip': assert 'Host: 192.0.2.10' in calls if mode == 'https': assert '--resolve' in calls and 'deployment.example:443:127.0.0.1' in calls assert '--insecure' not in calls and '"-k"' not in calls print(name + '/' + mode + ': passed')