vuls: init at 0.27.0 (#348530)
[NixPkgs.git] / nixos / tests / cgit.nix
blob073b141b14e73d2c496cef6e3b51fb1b980f4ce7
1 import ./make-test-python.nix ({ pkgs, ... }:
2 let
3   robotsTxt = pkgs.writeText "cgit-robots.txt" ''
4     User-agent: *
5     Disallow: /
6   '';
7 in {
8   name = "cgit";
9   meta = with pkgs.lib.maintainers; {
10     maintainers = [ schnusch ];
11   };
13   nodes = {
14     server = { ... }: {
15       services.cgit."localhost" = {
16         enable = true;
17         package = pkgs.cgit.overrideAttrs ({ postInstall, ... }: {
18           postInstall = ''
19             ${postInstall}
20             cp ${robotsTxt} "$out/cgit/robots.txt"
21           '';
22         });
23         nginx.location = "/(c)git/";
24         repos = {
25           some-repo = {
26             path = "/tmp/git/some-repo";
27             desc = "some-repo description";
28           };
29         };
30         settings = {
31           readme = [
32             ":README.md"
33             ":date.txt"
34           ];
35         };
36       };
38       environment.systemPackages = [ pkgs.git ];
39     };
40   };
42   testScript = { nodes, ... }: ''
43     start_all()
45     server.wait_for_unit("nginx.service")
46     server.wait_for_unit("network.target")
47     server.wait_for_open_port(80)
49     server.succeed("curl -fsS http://localhost/%28c%29git/cgit.css")
51     server.succeed("curl -fsS http://localhost/%28c%29git/robots.txt | diff -u - ${robotsTxt}")
53     server.succeed(
54         "curl -fsS http://localhost/%28c%29git/ | grep -F 'some-repo description'"
55     )
57     server.fail("curl -fsS http://localhost/robots.txt")
59     server.succeed("sudo -u cgit ${pkgs.writeShellScript "setup-cgit-test-repo" ''
60       set -e
61       git init --bare -b master /tmp/git/some-repo
62       git init -b master reference
63       cd reference
64       git remote add origin /tmp/git/some-repo
65       { echo -n "cgit NixOS Test at "; date; } > date.txt
66       git add date.txt
67       git -c user.name=test -c user.email=test@localhost commit -m 'add date'
68       git push -u origin master
69     ''}")
71     # test web download
72     server.succeed(
73         "curl -fsS 'http://localhost/%28c%29git/some-repo/plain/date.txt?id=master' | diff -u reference/date.txt -"
74     )
76     # test http clone
77     server.succeed(
78        "git clone http://localhost/%28c%29git/some-repo && diff -u reference/date.txt some-repo/date.txt"
79     )
81     # test list settings by greping for the fallback readme
82     server.succeed(
83         "curl -fsS 'http://localhost/%28c%29git/some-repo/about/' | grep -F 'cgit NixOS Test at'"
84     )
86     # add real readme
87     server.succeed("sudo -u cgit ${pkgs.writeShellScript "cgit-commit-readme" ''
88       set -e
89       echo '# cgit NixOS test README' > reference/README.md
90       git -C reference add README.md
91       git -C reference -c user.name=test -c user.email=test@localhost commit -m 'add readme'
92       git -C reference push
93     ''}")
95     # test list settings by greping for the real readme
96     server.succeed(
97         "curl -fsS 'http://localhost/%28c%29git/some-repo/about/' | grep -F '# cgit NixOS test README'"
98     )
99     server.fail(
100         "curl -fsS 'http://localhost/%28c%29git/some-repo/about/' | grep -F 'cgit NixOS Test at'"
101     )
102   '';