recordbox: 0.8.3 -> 0.9.0 (#367826)
[NixPkgs.git] / nixos / tests / web-servers / stargazer.nix
blob776b9095b4aed62bc9576e94de1c1071365ace39
1 { pkgs, lib, ... }:
2 let
3   test_script = pkgs.stdenv.mkDerivation {
4     pname = "stargazer-test-script";
5     inherit (pkgs.stargazer) version src;
6     buildInputs = with pkgs; [
7       (python3.withPackages (
8         ps: with ps; [
9           cryptography
10           urllib3
11         ]
12       ))
13     ];
14     dontBuild = true;
15     doCheck = false;
16     installPhase = ''
17       mkdir -p $out/bin
18       cp scripts/gemini-diagnostics $out/bin/test
19     '';
20   };
21   test_env = pkgs.stdenv.mkDerivation {
22     pname = "stargazer-test-env";
23     inherit (pkgs.stargazer) version src;
24     buildPhase = ''
25       cc test_data/cgi-bin/loop.c -o test_data/cgi-bin/loop
26     '';
27     doCheck = false;
28     installPhase = ''
29       mkdir -p $out
30       cp -r * $out/
31     '';
32   };
33   scgi_server = pkgs.stdenv.mkDerivation {
34     pname = "stargazer-test-scgi-server";
35     inherit (pkgs.stargazer) version src;
36     buildInputs = with pkgs; [ python3 ];
37     dontConfigure = true;
38     dontBuild = true;
39     doCheck = false;
40     installPhase = ''
41       mkdir -p $out/bin
42       cp scripts/scgi-server $out/bin/scgi-server
43     '';
44   };
47   name = "stargazer";
48   meta = with lib.maintainers; {
49     maintainers = [ gaykitty ];
50   };
52   nodes = {
53     geminiserver =
54       { pkgs, ... }:
55       {
56         services.stargazer = {
57           enable = true;
58           connectionLogging = false;
59           requestTimeout = 1;
60           routes = [
61             {
62               route = "localhost";
63               root = "${test_env}/test_data/test_site";
64             }
65             {
66               route = "localhost=/en.gmi";
67               root = "${test_env}/test_data/test_site";
68               lang = "en";
69               charset = "ascii";
70             }
71             {
72               route = "localhost~/(.*).gemini";
73               root = "${test_env}/test_data/test_site";
74               rewrite = "\\1.gmi";
75               lang = "en";
76               charset = "ascii";
77             }
78             {
79               route = "localhost=/plain.txt";
80               root = "${test_env}/test_data/test_site";
81               lang = "en";
82               charset = "ascii";
83               cert-path = "/var/lib/gemini/certs/localhost.crt";
84               key-path = "/var/lib/gemini/certs/localhost.key";
85             }
86             {
87               route = "localhost:/cgi-bin";
88               root = "${test_env}/test_data";
89               cgi = true;
90               cgi-timeout = 5;
91             }
92             {
93               route = "localhost:/scgi";
94               scgi = true;
95               scgi-address = "127.0.0.1:1099";
96             }
97             {
98               route = "localhost=/root";
99               redirect = "..";
100               permanent = true;
101             }
102             {
103               route = "localhost=/priv.gmi";
104               root = "${test_env}/test_data/test_site";
105               client-cert = "${test_env}/test_data/client_cert/good.crt";
106             }
107             {
108               route = "example.com~(.*)";
109               redirect = "gemini://localhost";
110               rewrite = "\\1";
111             }
112             {
113               route = "localhost:/no-exist";
114               root = "${test_env}/does_not_exist";
115             }
116             {
117               route = "localhost=/rss.xml";
118               root = "${test_env}/test_data/test_site";
119               mime-override = "application/atom+xml";
120             }
121           ];
122         };
123         systemd.services.scgi_server = {
124           after = [ "network.target" ];
125           wantedBy = [ "multi-user.target" ];
126           serviceConfig = {
127             ExecStart = "${scgi_server}/bin/scgi-server";
128           };
129         };
130       };
131     cgiTestServer =
132       { ... }:
133       {
134         users.users.cgi = {
135           isSystemUser = true;
136           group = "cgi";
137         };
138         users.groups.cgi = { };
139         services.stargazer = {
140           enable = true;
141           connectionLogging = false;
142           requestTimeout = 1;
143           allowCgiUser = true;
144           routes = [
145             {
146               route = "localhost:/cgi-bin";
147               root = "${test_env}/test_data";
148               cgi = true;
149               cgi-timeout = 5;
150               cgi-user = "cgi";
151             }
152           ];
153         };
154       };
155   };
157   testScript =
158     { nodes, ... }:
159     ''
160       geminiserver.wait_for_unit("scgi_server")
161       geminiserver.wait_for_open_port(1099)
162       geminiserver.wait_for_unit("stargazer")
163       cgiTestServer.wait_for_open_port(1965)
165       with subtest("stargazer test suite"):
166         response = geminiserver.succeed("sh -c 'cd ${test_env}; ${test_script}/bin/test'")
167         print(response)
168       with subtest("stargazer cgi-user test"):
169         response = cgiTestServer.succeed("sh -c 'cd ${test_env}; ${test_script}/bin/test --checks CGIVars'")
170         print(response)
171     '';