CH-J SM Mobileserverio valdymas per SSH
Meniu
Paskelbtas šaltinis

CH-J SM Mobile

Naršyti aplankus ir failus konkrečiai programai išleisti.

Atsisiųsti šaltinį ZIP
CH-J / SM Mobile 134 failai
sm-mobile-20261016T050549Z-3678f2a05fa9 Pridėta: · Pastatytas:
Failai
test_openssh.py Pridėta: Data neregistruota 2,9 KB · 51 eilutės
Atsiųsti failą
1#!/usr/bin/env python3
2"""Real, unprivileged loopback-only OpenSSH fixture on macOS/Linux. No Docker required."""
3import argparse,base64,getpass,json,os,pathlib,shutil,socket,subprocess,tempfile,time
4root=pathlib.Path(__file__).resolve().parents[1]
5p=argparse.ArgumentParser()
6p.add_argument('--device',help='Flutter device id; omitted runs host network tests')
7p.add_argument('--android',action='store_true',help='Use emulator host address 10.0.2.2')
8args=p.parse_args()
9sshd=shutil.which('sshd') or '/usr/sbin/sshd'
10# StrictModes requires a non-world-writable parent, unlike /tmp on macOS.
11cache=pathlib.Path.home()/'.cache/sm-mobile-tests';cache.mkdir(parents=True,exist_ok=True);cache.chmod(0o700)
12with tempfile.TemporaryDirectory(prefix='openssh-',dir=cache) as temporary:
13 fixture=pathlib.Path(temporary)
14 for name,phrase in [('host_key',''),('client_key','isolated-test-passphrase')]:
15 subprocess.run(['ssh-keygen','-q','-t','ed25519','-N',phrase,'-f',str(fixture/name)],check=True)
16 shutil.copy(fixture/'client_key.pub',fixture/'authorized_keys')
17 (fixture/'authorized_keys').chmod(0o600)
18 (fixture/'remote').mkdir()
19 (fixture/'sshd_config').write_text(f'''Port 22229
20ListenAddress 127.0.0.1
21HostKey {fixture}/host_key
22PidFile {fixture}/pid
23AuthorizedKeysFile {fixture}/authorized_keys
24StrictModes yes
25PubkeyAuthentication yes
26PasswordAuthentication no
27KbdInteractiveAuthentication no
28UsePAM no
29AllowUsers {getpass.getuser()}
30Subsystem sftp internal-sftp
31LogLevel ERROR
32''')
33 with (fixture/'server.log').open('w') as log:
34 server=subprocess.Popen([sshd,'-D','-e','-f',str(fixture/'sshd_config')],stdout=log,stderr=log)
35 try:
36 time.sleep(.5)
37 if server.poll() is not None: raise SystemExit((fixture/'server.log').read_text())
38 with socket.create_connection(('127.0.0.1',22229),timeout=3): pass
39 env={**os.environ,'SM_OPENSSH_TEST':'1','SM_TEST_KEY':str(fixture/'client_key'),'SM_TEST_REMOTE_DIR':str(fixture/'remote')}
40 if args.device:
41 fingerprint=subprocess.check_output(['ssh-keygen','-lf',str(fixture/'host_key.pub'),'-E','sha256'],text=True).split()[1]
42 defines={'SM_TEST_KEY_B64':base64.b64encode((fixture/'client_key').read_bytes()).decode(),
43 'SM_TEST_FINGERPRINT':fingerprint,'SM_TEST_USER':getpass.getuser(),'SM_TEST_HOST':'10.0.2.2' if args.android else '127.0.0.1'}
44 (fixture/'defines.json').write_text(json.dumps(defines));(fixture/'defines.json').chmod(0o600)
45 command=['flutter','test','integration_test/device_test.dart','-d',args.device,'--dart-define-from-file='+str(fixture/'defines.json')]
46 else: command=['flutter','test','test/network/openssh_test.dart','--reporter','expanded']
47 subprocess.run(command,cwd=root,env=env,check=True)
48 finally:
49 server.terminate()
50 try: server.wait(timeout=5)
51 except subprocess.TimeoutExpired: server.kill();server.wait()
SHA-2567b46c93edc8a7d5706a3195d938578161fcde4567c2ecb6f5b63955139b90ce7

CH-J Proprietary Software License 1.14 · Šaltinis pateiktas pagal CH-J Proprietary Software License 1.14. Jo prieinamumas nekeičia licencijos sąlygų ir nesuteikia papildomų teisių.

Archyvas SHA-256c486a807e4828998b9c57ab0f2e760f7980b31965fe118e89d3e1a5a2b65be65