summary refs log tree commit diff
path: root/nixos/tests/xandikos.nix
blob: 0fded20ff1a9cdea4776ed4769b0d82882345ddc (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
67
68
69
70
import ./make-test-python.nix (
  { pkgs, lib, ... }:

    {
      name = "xandikos";

      meta.maintainers = [ lib.maintainers."0x4A6F" ];

      nodes = {
        xandikos_client = {};
        xandikos_default = {
          networking.firewall.allowedTCPPorts = [ 8080 ];
          services.xandikos.enable = true;
        };
        xandikos_proxy = {
          networking.firewall.allowedTCPPorts = [ 80 8080 ];
          services.xandikos.enable = true;
          services.xandikos.address = "localhost";
          services.xandikos.port = 8080;
          services.xandikos.routePrefix = "/xandikos/";
          services.xandikos.extraOptions = [
            "--defaults"
          ];
          services.nginx = {
            enable = true;
            recommendedProxySettings = true;
            virtualHosts."xandikos" = {
              serverName = "xandikos.local";
              basicAuth.xandikos = "snakeOilPassword";
              locations."/xandikos/" = {
                proxyPass = "http://localhost:8080/";
              };
            };
          };
        };
      };

      testScript = ''
        start_all()

        with subtest("Xandikos default"):
            xandikos_default.wait_for_unit("multi-user.target")
            xandikos_default.wait_for_unit("xandikos.service")
            xandikos_default.wait_for_open_port(8080)
            xandikos_default.succeed("curl --fail http://localhost:8080/")
            xandikos_default.succeed(
                "curl -s --fail --location http://localhost:8080/ | grep -qi Xandikos"
            )
            xandikos_client.wait_for_unit("network.target")
            xandikos_client.fail("curl --fail http://xandikos_default:8080/")

        with subtest("Xandikos proxy"):
            xandikos_proxy.wait_for_unit("multi-user.target")
            xandikos_proxy.wait_for_unit("xandikos.service")
            xandikos_proxy.wait_for_open_port(8080)
            xandikos_proxy.succeed("curl --fail http://localhost:8080/")
            xandikos_proxy.succeed(
                "curl -s --fail --location http://localhost:8080/ | grep -qi Xandikos"
            )
            xandikos_client.wait_for_unit("network.target")
            xandikos_client.fail("curl --fail http://xandikos_proxy:8080/")
            xandikos_client.succeed(
                "curl -s --fail -u xandikos:snakeOilPassword -H 'Host: xandikos.local' http://xandikos_proxy/xandikos/ | grep -qi Xandikos"
            )
            xandikos_client.succeed(
                "curl -s --fail -u xandikos:snakeOilPassword -H 'Host: xandikos.local' http://xandikos_proxy/xandikos/user/ | grep -qi Xandikos"
            )
      '';
    }
)