summaryrefslogtreecommitdiffstats
path: root/nixos/tests/stirling-pdf-desktop.nix
blob: 4debcc213ade4d98ce875c0f4e8a04b67dfae62c (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{ lib, hostPkgs, ... }:
let
  port = 8080;
  server = "http://server:${toString port}";
in
{
  name = "stirling-pdf";
  meta = {
    maintainers = with lib.maintainers; [
      timhae
      phanirithvij
    ];
  };

  enableOCR = true;
  globalTimeout = 600;
  nodes = {
    server =
      { config, pkgs, ... }:
      {
        services.stirling-pdf = {
          enable = true;
          package = pkgs.stirling-pdf;
          environment = {
            SERVER_PORT = port;
            DISABLE_ADDITIONAL_FEATURES = false;
            SECURITY_ENABLELOGIN = true;
          };
        };
        networking.firewall.allowedTCPPorts = [ port ];
      };
    client =
      { config, pkgs, ... }:
      {
        virtualisation = {
          memorySize = 4096;
          cores = 4;
          qemu.options = [
            # Force qemu at 640x480 resolution
            "-vga none -device virtio-gpu-pci,xres=640,yres=480"
          ];
        };
        imports = [ ./common/wayland-cage.nix ];
        services.cage.program = lib.getExe pkgs.stirling-pdf-desktop;
        systemd.tmpfiles.settings."stirling-provisioning.json"."/etc/stirling-pdf/stirling-provisioning.json"."L+".argument =
          builtins.toString (
            pkgs.writeText "stirling-provisioning.json" ''
              {
                "serverUrl": "${server}",
                "lockConnectionMode": true
              }
            ''
          );
        programs.ydotool.enable = true;
        users.users.alice.extraGroups = [ "ydotool" ];
      };
  };

  testScript = ''
    server.start()
    server.wait_for_unit("stirling-pdf.service")
    server.wait_for_console_text("Stirling-PDF Started")

    # initial login
    client.start()
    client.wait_for_text("Sign in to Server")
    client.send_chars("admin", 0.1)
    client.send_key("tab", 1)
    client.send_chars("stirling\n", 0.1)

    # skip telemetry prompt
    client.wait_for_text("analytics")
    client.send_key("shift-tab", 1)
    client.send_key("tab", 1)
    client.send_key("tab", 1)
    client.send_key("kp_enter", 1)

    # update password
    client.wait_for_text("password")
    client.send_key("tab", 1)
    client.send_key("shift-tab", 1)
    client.send_key("shift-tab", 1)
    client.send_key("shift-tab", 1)
    client.send_chars("stirling2", 0.1)
    client.send_key("tab", 1)
    client.send_chars("stirling2", 0.1)
    client.send_key("tab", 1)
    client.send_key("kp_enter", 1)

    # final login
    client.wait_for_text("Sign in to Server")
    client.send_chars("admin", 0.1)
    client.send_key("tab", 1)
    client.send_chars("stirling2\n", 0.1)
    client.wait_for_text("Welcome to Stirling")
    client.send_key("kp_enter", 1)

    # version prompt
    client.wait_for_text("Config")
    client.execute("ydotool mousemove -a -- 290 220") # Config button
    client.execute("ydotool click 0xC0")
    client.wait_for_text("Current Frontend Version")
    client.screenshot("stirling-pdf-version")
  '';

  # Debug interactively with:
  # - nix-build -A nixosTests.stirling-pdf-desktop.driverInteractive
  # - ./result/bin/nixos-test-driver
  # - run_tests()
  interactive.sshBackdoor.enable = true;
  interactive.nodes.client =
    { pkgs, ... }:
    {
      # make the mouse visible
      services.cage.environment.WLR_NO_HARDWARE_CURSORS = "1";
    };
  interactive.nodes.server =
    { ... }:
    {
      virtualisation.forwardPorts = [
        {
          from = "host";
          host.port = port;
          guest.port = port;
        }
      ];
      # forwarded ports need to be accessible
      networking.firewall.allowedTCPPorts = [ port ];
    };
}