1import ./make-test-python.nix ({ pkgs, ... }:
2
3let
4 template-bootstrap3 = pkgs.stdenv.mkDerivation rec {
5 name = "bootstrap3";
6 version = "2022-07-27";
7 src = pkgs.fetchFromGitHub {
8 owner = "giterlizzi";
9 repo = "dokuwiki-template-bootstrap3";
10 rev = "v${version}";
11 hash = "sha256-B3Yd4lxdwqfCnfmZdp+i/Mzwn/aEuZ0ovagDxuR6lxo=";
12 };
13 installPhase = "mkdir -p $out; cp -R * $out/";
14 };
15
16
17 plugin-icalevents = pkgs.stdenv.mkDerivation rec {
18 name = "icalevents";
19 version = "2017-06-16";
20 src = pkgs.fetchzip {
21 stripRoot = false;
22 url = "https://github.com/real-or-random/dokuwiki-plugin-icalevents/releases/download/${version}/dokuwiki-plugin-icalevents-${version}.zip";
23 hash = "sha256-IPs4+qgEfe8AAWevbcCM9PnyI0uoyamtWeg4rEb+9Wc=";
24 };
25 installPhase = "mkdir -p $out; cp -R * $out/";
26 };
27
28 acronymsFile = pkgs.writeText "acronyms.local.conf" ''
29 r13y reproducibility
30 '';
31
32 dwWithAcronyms = pkgs.dokuwiki.overrideAttrs (prev: {
33 installPhase = prev.installPhase or "" + ''
34 ln -sf ${acronymsFile} $out/share/dokuwiki/conf/acronyms.local.conf
35 '';
36 });
37
38 mkNode = webserver: { ... }: {
39 services.dokuwiki = {
40 inherit webserver;
41
42 sites = {
43 "site1.local" = {
44 templates = [ template-bootstrap3 ];
45 settings = {
46 useacl = false;
47 userewrite = true;
48 template = "bootstrap3";
49 };
50 };
51 "site2.local" = {
52 package = dwWithAcronyms;
53 usersFile = "/var/lib/dokuwiki/site2.local/users.auth.php";
54 plugins = [ plugin-icalevents ];
55 settings = {
56 useacl = true;
57 superuser = "admin";
58 title._file = titleFile;
59 plugin.dummy.empty = "This is just for testing purposes";
60 };
61 acl = [
62 { page = "*";
63 actor = "@ALL";
64 level = "read"; }
65 { page = "acl-test";
66 actor = "@ALL";
67 level = "none"; }
68 ];
69 pluginsConfig = {
70 authad = false;
71 authldap = false;
72 authmysql = false;
73 authpgsql = false;
74 tag = false;
75 icalevents = true;
76 };
77 };
78 };
79 };
80
81 networking.firewall.allowedTCPPorts = [ 80 ];
82 networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
83 };
84
85 titleFile = pkgs.writeText "dokuwiki-title" "DokuWiki on site2";
86in {
87 name = "dokuwiki";
88 meta = with pkgs.lib; {
89 maintainers = with maintainers; [
90 _1000101
91 onny
92 e1mo
93 ];
94 };
95
96 nodes = {
97 dokuwiki_nginx = mkNode "nginx";
98 dokuwiki_caddy = mkNode "caddy";
99 };
100
101 testScript = ''
102
103 start_all()
104
105 dokuwiki_nginx.wait_for_unit("nginx")
106 dokuwiki_caddy.wait_for_unit("caddy")
107
108 site_names = ["site1.local", "site2.local"]
109
110 for machine in (dokuwiki_nginx, dokuwiki_caddy):
111 for site_name in site_names:
112 machine.wait_for_unit(f"phpfpm-dokuwiki-{site_name}")
113
114 machine.succeed("curl -sSfL http://site1.local/ | grep 'DokuWiki'")
115 machine.fail("curl -sSfL 'http://site1.local/doku.php?do=login' | grep 'Login'")
116
117 machine.succeed("curl -sSfL http://site2.local/ | grep 'DokuWiki on site2'")
118 machine.succeed("curl -sSfL 'http://site2.local/doku.php?do=login' | grep 'Login'")
119
120 with subtest("ACL Operations"):
121 machine.succeed(
122 "echo 'admin:$2y$10$ijdBQMzSVV20SrKtCna8gue36vnsbVm2wItAXvdm876sshI4uwy6S:Admin:admin@example.test:user' >> /var/lib/dokuwiki/site2.local/users.auth.php",
123 "curl -sSfL -d 'u=admin&p=password' --cookie-jar cjar 'http://site2.local/doku.php?do=login'",
124 "curl -sSfL --cookie cjar --cookie-jar cjar 'http://site2.local/doku.php?do=login' | grep 'Logged in as: <bdi>Admin</bdi>'",
125 )
126
127 # Ensure the generated ACL is valid
128 machine.succeed(
129 "echo 'No Hello World! for @ALL here' >> /var/lib/dokuwiki/site2.local/data/pages/acl-test.txt",
130 "curl -sSL 'http://site2.local/doku.php?id=acl-test' | grep 'Permission Denied'"
131 )
132
133 with subtest("Customizing Dokuwiki"):
134 machine.succeed(
135 "echo 'r13y is awesome!' >> /var/lib/dokuwiki/site2.local/data/pages/acronyms-test.txt",
136 "curl -sSfL 'http://site2.local/doku.php?id=acronyms-test' | grep '<abbr title=\"reproducibility\">r13y</abbr>'",
137 )
138
139 # Testing if plugins (a) be correctly loaded and (b) configuration to enable them works
140 machine.succeed(
141 "echo '~~INFO:syntaxplugins~~' >> /var/lib/dokuwiki/site2.local/data/pages/plugin-list.txt",
142 "curl -sSfL 'http://site2.local/doku.php?id=plugin-list' | grep 'plugin:icalevents'",
143 "curl -sSfL 'http://site2.local/doku.php?id=plugin-list' | (! grep 'plugin:tag')",
144 )
145
146 # Test if theme is applied and working correctly (no weird relative PHP import errors)
147 machine.succeed(
148 "curl -sSfL 'http://site1.local/doku.php' | grep 'bootstrap3/images/logo.png'",
149 "curl -sSfL 'http://site1.local/lib/exe/css.php' | grep 'bootstrap3'",
150 "curl -sSfL 'http://site1.local/lib/tpl/bootstrap3/css.php'",
151 )
152
153
154 # Just to ensure both Webserver configurations are consistent in allowing that
155 with subtest("Rewriting"):
156 machine.succeed(
157 "echo 'Hello, NixOS!' >> /var/lib/dokuwiki/site1.local/data/pages/rewrite-test.txt",
158 "curl -sSfL http://site1.local/rewrite-test | grep 'Hello, NixOS!'",
159 )
160 '';
161})