#!/usr/bin/env python3 """Optional Linux SSH/password/monitor integration fixture; never an app dependency.""" import argparse,os,pathlib,secrets,socket,subprocess,time root=pathlib.Path(__file__).resolve().parents[1] p=argparse.ArgumentParser() p.add_argument('--context',help='Docker context, e.g. colima-sm-mobile-test') args=p.parse_args() docker=['docker']+(['--context',args.context] if args.context else []) image='lscr.io/linuxserver/openssh-server@sha256:0f535b0faa7448511b23528165e9fbd4f1fe563b861b3dcaa5ddb0ddbfe2254c' name='sm-mobile-linux-'+secrets.token_hex(6) password=secrets.token_urlsafe(24) env={**os.environ,'USER_PASSWORD':password} subprocess.run(docker+['run','--rm','-d','--name',name,'--memory','256m','--cpus','1', '-p','127.0.0.1:22239:2222','-e','USER_NAME=smtest','-e','PASSWORD_ACCESS=true', '-e','USER_PASSWORD','-e','SUDO_ACCESS=false',image],env=env,check=True,stdout=subprocess.DEVNULL) try: for attempt in range(80): try: with socket.create_connection(('127.0.0.1',22239),timeout=1) as probe: if not probe.recv(128).startswith(b'SSH-'):raise OSError('SSH is not ready') break except OSError:time.sleep(.25) else:raise SystemExit('Linux SSH fixture did not become ready.') files=subprocess.check_output(docker+['exec',name,'find','/config','-name','*ed25519*.pub'],text=True).splitlines() if len(files)!=1:raise SystemExit('Unexpected host-key files in Linux fixture.') fingerprint=subprocess.check_output(docker+['exec',name,'ssh-keygen','-lf',files[0],'-E','sha256'],text=True).split()[1] print('Testing real Linux OpenSSH using pinned image '+image,flush=True) subprocess.run(['flutter','test','test/network/linux_test.dart','--reporter','expanded'],cwd=root, env={**os.environ,'SM_LINUX_TEST':'1','SM_TEST_PASSWORD':password,'SM_TEST_FINGERPRINT':fingerprint},check=True) finally: subprocess.run(docker+['rm','-f',name],check=False,stdout=subprocess.DEVNULL)