1 import ./make-test-python.nix ({ pkgs, lib, ... }:
3 inherit (import ./ssh-keys.nix pkgs)
4 snakeOilPrivateKey snakeOilPublicKey;
6 setUpPrivateKey = name: ''
9 "chmod 700 /root/.ssh",
10 "cat '${snakeOilPrivateKey}' > /root/.ssh/id_snakeoil",
11 "chmod 600 /root/.ssh/id_snakeoil",
13 ${name}.wait_for_file("/root/.ssh/id_snakeoil")
16 sshOpts = "-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oIdentityFile=/root/.ssh/id_snakeoil";
20 name = "tmate-ssh-server";
24 services.tmate-ssh-server = {
31 environment.systemPackages = [ pkgs.tmate ];
32 services.openssh.enable = true;
33 users.users.root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
36 environment.systemPackages = [ pkgs.openssh ];
42 server.wait_for_unit("tmate-ssh-server.service")
43 server.wait_for_open_port(2223)
44 server.wait_for_file("/etc/tmate-ssh-server-keys/ssh_host_ed25519_key.pub")
45 server.wait_for_file("/etc/tmate-ssh-server-keys/ssh_host_rsa_key.pub")
46 server.succeed("tmate-client-config > /tmp/tmate.conf")
47 server.wait_for_file("/tmp/tmate.conf")
49 ${setUpPrivateKey "server"}
50 client.wait_for_unit("sshd.service")
51 client.wait_for_open_port(22)
52 server.succeed("scp ${sshOpts} /tmp/tmate.conf client:/tmp/tmate.conf")
54 client.wait_for_file("/tmp/tmate.conf")
55 client.wait_until_tty_matches("1", "login:")
56 client.send_chars("root\n")
58 client.send_chars("tmate -f /tmp/tmate.conf\n")
60 client.send_chars("q")
62 client.send_chars("tmate display -p '#{tmate_ssh}' > /tmp/ssh_command\n")
63 client.wait_for_file("/tmp/ssh_command")
64 ssh_cmd = client.succeed("cat /tmp/ssh_command")
66 client2.succeed("mkdir -p ~/.ssh; ssh-keyscan -4 -p 2223 server > ~/.ssh/known_hosts")
67 client2.wait_until_tty_matches("1", "login:")
68 client2.send_chars("root\n")
70 client2.send_chars(ssh_cmd.strip() + "\n")
72 client2.send_chars("touch /tmp/client_2\n")
74 client.wait_for_file("/tmp/client_2")