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.wait_for_unit("network-online.target")
32
33 # wait for upterm port to be reachable
34 client1.wait_until_succeeds("nc -z -v server 1337")
35
36 # Add SSH hostkeys from the server to both clients
37 # uptermd needs an '@cert-authority entry so we need to modify the known_hosts file
38 client1.execute("mkdir -p ~/.ssh && ssh -o StrictHostKeyChecking=no -p 1337 server ls")
39 client1.execute("echo @cert-authority $(cat ~/.ssh/known_hosts) > ~/.ssh/known_hosts")
40 client2.execute("mkdir -p ~/.ssh && ssh -o StrictHostKeyChecking=no -p 1337 server ls")
41 client2.execute("echo @cert-authority $(cat ~/.ssh/known_hosts) > ~/.ssh/known_hosts")
42
43 client1.wait_for_unit("multi-user.target")
44 client1.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
45 client1.wait_until_tty_matches("1", "login: ")
46 client1.send_chars("root\n")
47 client1.wait_until_succeeds("pgrep -u root bash")
48
49 client1.execute("ssh-keygen -t ed25519 -N \"\" -f /root/.ssh/id_ed25519")
50 client1.send_chars("TERM=xterm upterm host --server ssh://server:1337 --force-command hostname -- bash > /tmp/session-details\n")
51 client1.wait_for_file("/tmp/session-details")
52 client1.send_key("q")
53
54 # uptermd can't connect if we don't have a keypair
55 client2.execute("ssh-keygen -t ed25519 -N \"\" -f /root/.ssh/id_ed25519")
56
57 # Grep the ssh connect command from the output of 'upterm host'
58 ssh_command = client1.succeed("grep 'SSH Session' /tmp/session-details | cut -d':' -f2-").strip()
59
60 # Connect with client2. Because we used '--force-command hostname' we should get "client1" as the output
61 output = client2.succeed(ssh_command)
62
63 assert output.strip() == "client1"
64 '';
65})