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