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