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