feat: 支持局域网 HTTPS 直连并持久化插件连接配置
This commit is contained in:
1 parent
9eba4556db
commit
2203afde3c
15 files changed
+486
-17
No files matched your search
@@ -6,6 +6,7 @@ import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import ssl
|
||||
import time
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
@@ -19,6 +20,7 @@ def main():
|
||||
parser.add_argument('--url', default='http://127.0.0.1:8765')
|
||||
parser.add_argument('--task', default=':app:assembleDebug')
|
||||
parser.add_argument('--adb', default='adb')
|
||||
parser.add_argument('--server-cert', help='Trusted server public PEM certificate for LAN HTTPS')
|
||||
parser.add_argument('--device', help='Explicit adb device serial; omit to download only')
|
||||
args = parser.parse_args()
|
||||
token = os.environ.get('REMOTE_BUILD_TOKEN', '')
|
||||
@@ -38,7 +40,8 @@ def main():
|
||||
data = json.dumps(body).encode() if body is not None else None
|
||||
req = urllib.request.Request(endpoint + '/api/v1' + path, data=data, method=method,
|
||||
headers={'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json'})
|
||||
with urllib.request.urlopen(req, timeout=300) as response:
|
||||
context = ssl.create_default_context(cafile=args.server_cert) if args.server_cert else None
|
||||
with urllib.request.urlopen(req, timeout=300, context=context) as response:
|
||||
result = response.read()
|
||||
return result if '/artifacts/' in path else json.loads(result)
|
||||
|
||||
|
||||
+18
-3
@@ -18,6 +18,12 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
class SmokeTest(unittest.TestCase):
|
||||
def test_sync_build_download_and_second_revision(self):
|
||||
self.exercise(False)
|
||||
|
||||
def test_https_sync_build_download_and_second_revision(self):
|
||||
self.exercise(True)
|
||||
|
||||
def exercise(self, secure):
|
||||
binary = ROOT / 'dist' / ('remotecompile-windows-amd64.exe' if os.name == 'nt' else 'remotecompile')
|
||||
if not binary.exists():
|
||||
self.skipTest(f'Build service binary first: {binary}')
|
||||
@@ -34,20 +40,29 @@ class SmokeTest(unittest.TestCase):
|
||||
with socket.socket() as sock:
|
||||
sock.bind(('127.0.0.1', 0))
|
||||
port = sock.getsockname()[1]
|
||||
endpoint = f'http://127.0.0.1:{port}'
|
||||
endpoint = f'{"https" if secure else "http"}://127.0.0.1:{port}'
|
||||
env = dict(os.environ, REMOTE_BUILD_TOKEN='test-only-token-abcdefghijklmnopqrstuvwxyz')
|
||||
process = subprocess.Popen([str(binary), '-listen', f'127.0.0.1:{port}', '-data', str(root / 'data')], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
command = [str(binary), '-listen', f'127.0.0.1:{port}', '-data', str(root / 'data')]
|
||||
context = None
|
||||
if secure:
|
||||
import ssl
|
||||
subprocess.run([str(binary), '-init-tls-host', '127.0.0.1', '-tls-dir', str(root/'tls')], check=True, capture_output=True)
|
||||
command += ['-tls-cert', str(root/'tls/server.crt'), '-tls-key', str(root/'tls/server.key')]
|
||||
context = ssl.create_default_context(cafile=str(root/'tls/server.crt'))
|
||||
process = subprocess.Popen(command, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
try:
|
||||
for _ in range(100):
|
||||
try:
|
||||
req = urllib.request.Request(endpoint + '/api/v1/health', headers={'Authorization': 'Bearer ' + env['REMOTE_BUILD_TOKEN']})
|
||||
with urllib.request.urlopen(req, timeout=1):
|
||||
with urllib.request.urlopen(req, timeout=1, context=context):
|
||||
break
|
||||
except OSError:
|
||||
time.sleep(.05)
|
||||
else:
|
||||
self.fail('Service did not start')
|
||||
command = [sys.executable, str(ROOT / 'client' / 'remote_run.py'), str(source), '--url', endpoint]
|
||||
if secure:
|
||||
command += ['--server-cert', str(root/'tls/server.crt')]
|
||||
first = subprocess.run(command, env=env, capture_output=True, text=True, timeout=30)
|
||||
self.assertEqual(first.returncode, 0, first.stderr)
|
||||
self.assertEqual(next((source / '.remotecompile').glob('*.apk')).read_bytes(), b'first')
|
||||
|
||||
Reference in new issue
Block a user