1{ pkgs, ... }: 2 3let 4 client = 5 { pkgs, ... }: 6 { 7 environment.systemPackages = [ pkgs.upterm ]; 8 }; 9in 10{ 11 name = "uptermd"; 12 meta = with pkgs.lib.maintainers; { 13 maintainers = [ fleaz ]; 14 }; 15 16 nodes = { 17 server = 18 { config, ... }: 19 { 20 services.uptermd = { 21 enable = true; 22 openFirewall = true; 23 port = 1337; 24 }; 25 }; 26 client1 = client; 27 client2 = client; 28 }; 29 30 testScript = '' 31 start_all() 32 33 server.wait_for_unit("uptermd.service") 34 server.systemctl("start network-online.target") 35 server.wait_for_unit("network-online.target") 36 37 # wait for upterm port to be reachable 38 client1.wait_until_succeeds("nc -z -v server 1337") 39 40 # Add SSH hostkeys from the server to both clients 41 # uptermd needs an '@cert-authority entry so we need to modify the known_hosts file 42 client1.execute("mkdir -p ~/.ssh && ssh -o StrictHostKeyChecking=no -p 1337 server ls") 43 client1.execute("echo @cert-authority $(cat ~/.ssh/known_hosts) > ~/.ssh/known_hosts") 44 client2.execute("mkdir -p ~/.ssh && ssh -o StrictHostKeyChecking=no -p 1337 server ls") 45 client2.execute("echo @cert-authority $(cat ~/.ssh/known_hosts) > ~/.ssh/known_hosts") 46 47 client1.wait_for_unit("multi-user.target") 48 client1.wait_until_succeeds("pgrep -f 'agetty.*tty1'") 49 client1.wait_until_tty_matches("1", "login: ") 50 client1.send_chars("root\n") 51 client1.wait_until_succeeds("pgrep -u root bash") 52 53 client1.execute("ssh-keygen -t ed25519 -N \"\" -f /root/.ssh/id_ed25519") 54 client1.send_chars("TERM=xterm upterm host --server ssh://server:1337 --force-command hostname -- bash > /tmp/session-details\n") 55 client1.wait_for_file("/tmp/session-details") 56 client1.send_key("q") 57 58 # uptermd can't connect if we don't have a keypair 59 client2.execute("ssh-keygen -t ed25519 -N \"\" -f /root/.ssh/id_ed25519") 60 61 # Grep the ssh connect command from the output of 'upterm host' 62 ssh_command = client1.succeed("grep 'SSH Session' /tmp/session-details | cut -d':' -f2-").strip() 63 64 # Connect with client2. Because we used '--force-command hostname' we should get "client1" as the output 65 output = client2.succeed(ssh_command) 66 67 assert output.strip() == "client1" 68 ''; 69}