aboutsummaryrefslogtreecommitdiffstats
path: root/tests/by-name/sh/sharkey-cpu/test.nix
blob: 89bc7cb956123adf6d33f56909fe01475fa647f9 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{
  packageSets,
  vhack,
  ...
}: let
  pkgs = packageSets.stable;
in
  vhack.runTest {
    name = "sharkey-cpu";
    ignore = true;

    nodes = {
      server = {config, ...}: {
        vhack = {
          persist.enable = true;
          nginx.enable = true;
          sharkey = {
            enable = true;
            fqdn = "sharkey.server";
          };
        };
        systemd.services = {
          # Avoid an error from this service.
          "acme-sharkey.server".enable = false;

          # Test that sharkey's hardening still allows access to the CPUs.
          sharkey.serviceConfig.ExecStart = let
            nodejs = pkgs.lib.getExe pkgs.nodejs;
            script = pkgs.writeTextFile {
              name = "script.js";
              text =
                # js
                ''
                  import * as os from 'node:os';

                  var cpus = os.cpus()

                  if (cpus.length != 0) {
                    console.log(cpus[0].model)
                  } else {
                    // Fail?
                  }

                  while (true) {
                  }
                '';
            };
          in
            pkgs.lib.mkForce "${nodejs} ${script}";
        };
      };
    };

    services = [
      {server = "sharkey.service";}
    ];

    testScript = {...}:
    # Python
    ''
      from time import sleep

      # Give the service time to run.
      sleep(3)
    '';
  }