about summary refs log tree commit diff
path: root/nixos/tests/web-servers/stargazer.nix
blob: 52bc93af171940bd88e7a55808dd0357a0accc58 (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
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
131
132
{ pkgs, lib, ... }:
let
  test_script = pkgs.stdenv.mkDerivation {
    pname = "stargazer-test-script";
    inherit (pkgs.stargazer) version src;
    buildInputs = with pkgs; [ (python3.withPackages (ps: with ps; [ cryptography urllib3 ])) ];
    dontBuild = true;
    doCheck = false;
    installPhase = ''
      mkdir -p $out/bin
      cp scripts/gemini-diagnostics $out/bin/test
    '';
  };
  test_env = pkgs.stdenv.mkDerivation {
    pname = "stargazer-test-env";
    inherit (pkgs.stargazer) version src;
    buildPhase = ''
      cc test_data/cgi-bin/loop.c -o test_data/cgi-bin/loop
    '';
    doCheck = false;
    installPhase = ''
      mkdir -p $out
      cp -r * $out/
    '';
  };
  scgi_server = pkgs.stdenv.mkDerivation {
    pname = "stargazer-test-scgi-server";
    inherit (pkgs.stargazer) version src;
    buildInputs = with pkgs; [ python3 ];
    dontConfigure = true;
    dontBuild = true;
    doCheck = false;
    installPhase = ''
      mkdir -p $out/bin
      cp scripts/scgi-server $out/bin/scgi-server
    '';
  };
in
{
  name = "stargazer";
  meta = with lib.maintainers; { maintainers = [ gaykitty ]; };

  nodes = {
    geminiserver = { pkgs, ... }: {
      services.stargazer = {
        enable = true;
        connectionLogging = false;
        requestTimeout = 1;
        routes = [
          {
            route = "localhost";
            root = "${test_env}/test_data/test_site";
          }
          {
            route = "localhost=/en.gmi";
            root = "${test_env}/test_data/test_site";
            lang = "en";
            charset = "ascii";
          }
          {
            route = "localhost~/(.*).gemini";
            root = "${test_env}/test_data/test_site";
            rewrite = "\\1.gmi";
            lang = "en";
            charset = "ascii";
          }
          {
            route = "localhost=/plain.txt";
            root = "${test_env}/test_data/test_site";
            lang = "en";
            charset = "ascii";
            cert-path = "/var/lib/gemini/certs/localhost.crt";
            key-path = "/var/lib/gemini/certs/localhost.key";
          }
          {
            route = "localhost:/cgi-bin";
            root = "${test_env}/test_data";
            cgi = true;
            cgi-timeout = 5;
          }
          {
            route = "localhost:/scgi";
            scgi = true;
            scgi-address = "127.0.0.1:1099";
          }
          {
            route = "localhost=/root";
            redirect = "..";
            permanent = true;
          }
          {
            route = "localhost=/priv.gmi";
            root = "${test_env}/test_data/test_site";
            client-cert = "${test_env}/test_data/client_cert/good.crt";
          }
          {
            route = "example.com~(.*)";
            redirect = "gemini://localhost";
            rewrite = "\\1";
          }
          {
            route = "localhost:/no-exist";
            root = "${test_env}/does_not_exist";
          }
          {
            route = "localhost=/rss.xml";
            root = "${test_env}/test_data/test_site";
            mime-override = "application/atom+xml";
          }
        ];
      };
      systemd.services.scgi_server = {
        after = [ "network.target" ];
        wantedBy = [ "multi-user.target" ];
        serviceConfig = {
          ExecStart = "${scgi_server}/bin/scgi-server";
        };
      };
    };
  };

  testScript = { nodes, ... }: ''
    geminiserver.wait_for_unit("scgi_server")
    geminiserver.wait_for_open_port(1099)
    geminiserver.wait_for_unit("stargazer")
    geminiserver.wait_for_open_port(1965)

    with subtest("stargazer test suite"):
      response = geminiserver.succeed("sh -c 'cd ${test_env}; ${test_script}/bin/test'")
      print(response)
  '';
}