about summary refs log tree commit diff
path: root/nixos/tests/endlessh.nix
blob: be742a749fdd88d68f8d64986a210acb0227eeff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import ./make-test-python.nix ({ lib, pkgs, ... }:
{
  name = "endlessh";
  meta.maintainers = with lib.maintainers; [ azahi ];

  nodes = {
    server = { ... }: {
      services.endlessh = {
        enable = true;
        openFirewall = true;
      };

      specialisation = {
        unprivileged.configuration.services.endlessh.port = 2222;

        privileged.configuration.services.endlessh.port = 22;
      };
    };

    client = { pkgs, ... }: {
      environment.systemPackages = with pkgs; [ curl netcat ];
    };
  };

  testScript = ''
    def activate_specialisation(name: str):
        server.succeed(f"/run/booted-system/specialisation/{name}/bin/switch-to-configuration test >&2")

    start_all()

    with subtest("Unprivileged"):
        activate_specialisation("unprivileged")
        server.wait_for_unit("endlessh.service")
        server.wait_for_open_port(2222)
        client.succeed("nc -dvW5 server 2222")

    with subtest("Privileged"):
        activate_specialisation("privileged")
        server.wait_for_unit("endlessh.service")
        server.wait_for_open_port(22)
        client.succeed("nc -dvW5 server 22")
  '';
})