summary refs log tree commit diff
path: root/nixos/tests/nginx-pubhtml.nix
blob: 6e1e605628e9a01f82cd8ae28c4b6308ee20b199 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import ./make-test-python.nix {
  name = "nginx-pubhtml";

  machine = { pkgs, ... }: {
    systemd.services.nginx.serviceConfig.ProtectHome = "read-only";
    services.nginx.enable = true;
    services.nginx.virtualHosts.localhost = {
      locations."~ ^/\\~([a-z0-9_]+)(/.*)?$".alias = "/home/$1/public_html$2";
    };
    users.users.foo.isNormalUser = true;
  };

  testScript = ''
    machine.wait_for_unit("nginx")
    machine.wait_for_open_port(80)
    machine.succeed("chmod 0711 /home/foo")
    machine.succeed("su -c 'mkdir -p /home/foo/public_html' foo")
    machine.succeed("su -c 'echo bar > /home/foo/public_html/bar.txt' foo")
    machine.succeed('test "$(curl -fvvv http://localhost/~foo/bar.txt)" = bar')
  '';
}