···
1
+
import ./make-test-python.nix ({ lib, pkgs, ... }:
password = "some_password";
4
-
port = builtins.toString 5232;
7
+
filesystem_folder = "/data/radicale";
9
+
cli = "${pkgs.calendar-cli}/bin/calendar-cli --caldav-user ${user} --caldav-pass ${password}";
12
+
meta.maintainers = with lib.maintainers; [ dotlambda ];
6
-
common = { pkgs, ... }: {
14
+
machine = { pkgs, ... }: {
12
-
htpasswd_filename = /etc/radicale/htpasswd
13
-
htpasswd_encryption = bcrypt
16
-
filesystem_folder = /tmp/collections
20
+
htpasswd_filename = "/etc/radicale/users";
21
+
htpasswd_encryption = "bcrypt";
24
+
inherit filesystem_folder;
25
+
hook = "git add -A && (git diff --cached --quiet || git commit -m 'Changes by '%(user)s)";
27
+
logging.level = "info";
32
+
collection = "{user}";
37
+
collection = "{user}/[^/]+";
42
+
systemd.services.radicale.path = [ pkgs.git ];
43
+
environment.systemPackages = [ pkgs.git ];
44
+
systemd.tmpfiles.rules = [ "d ${filesystem_folder} 0750 radicale radicale -" ];
# WARNING: DON'T DO THIS IN PRODUCTION!
# This puts unhashed secrets directly into the Nix store for ease of testing.
21
-
environment.etc."radicale/htpasswd".source = pkgs.runCommand "htpasswd" {} ''
47
+
environment.etc."radicale/users".source = pkgs.runCommand "htpasswd" {} ''
${pkgs.apacheHttpd}/bin/htpasswd -bcB "$out" ${user} ${password}
28
-
import ./make-test-python.nix ({ lib, ... }@args: {
30
-
meta.maintainers = with lib.maintainers; [ aneeshusa infinisil ];
33
-
radicale = radicale1; # Make the test script read more nicely
34
-
radicale1 = lib.recursiveUpdate (common args) {
35
-
nixpkgs.overlays = [
37
-
radicale1 = super.radicale1.overrideAttrs (oldAttrs: {
38
-
propagatedBuildInputs = with self.pythonPackages;
39
-
(oldAttrs.propagatedBuildInputs or []) ++ [ passlib ];
43
-
system.stateVersion = "17.03";
45
-
radicale1_export = lib.recursiveUpdate radicale1 {
46
-
services.radicale.extraArgs = [
47
-
"--export-storage" "/tmp/collections-new"
49
-
system.stateVersion = "17.03";
51
-
radicale2_verify = lib.recursiveUpdate radicale2 {
52
-
services.radicale.extraArgs = [ "--debug" "--verify-storage" ];
53
-
system.stateVersion = "17.09";
55
-
radicale2 = lib.recursiveUpdate (common args) {
56
-
system.stateVersion = "17.09";
58
-
radicale3 = lib.recursiveUpdate (common args) {
59
-
system.stateVersion = "20.09";
63
-
# This tests whether the web interface is accessible to an authenticated user
64
-
testScript = { nodes }: let
65
-
switchToConfig = nodeName: let
66
-
newSystem = nodes.${nodeName}.config.system.build.toplevel;
67
-
in "${newSystem}/bin/switch-to-configuration test";
69
-
with subtest("Check Radicale 1 functionality"):
71
-
"${switchToConfig "radicale1"} >&2"
73
-
radicale.wait_for_unit("radicale.service")
74
-
radicale.wait_for_open_port(${port})
76
-
"curl --fail http://${user}:${password}@localhost:${port}/someuser/calendar.ics/"
79
-
with subtest("Export data in Radicale 2 format"):
80
-
radicale.succeed("systemctl stop radicale")
81
-
radicale.succeed("ls -al /tmp/collections")
82
-
radicale.fail("ls -al /tmp/collections-new")
84
-
with subtest("Radicale exits immediately after exporting storage"):
86
-
"${switchToConfig "radicale1_export"} >&2"
88
-
radicale.wait_until_fails("systemctl status radicale")
89
-
radicale.succeed("ls -al /tmp/collections")
90
-
radicale.succeed("ls -al /tmp/collections-new")
92
-
with subtest("Verify data in Radicale 2 format"):
93
-
radicale.succeed("rm -r /tmp/collections/${user}")
94
-
radicale.succeed("mv /tmp/collections-new/collection-root /tmp/collections")
96
-
"${switchToConfig "radicale2_verify"} >&2"
98
-
radicale.wait_until_fails("systemctl status radicale")
100
-
(retcode, logs) = radicale.execute("journalctl -u radicale -n 10")
102
-
retcode == 0 and "Verifying storage" in logs
103
-
), "Radicale 2 didn't verify storage"
105
-
"failed" not in logs and "exception" not in logs
106
-
), "storage verification failed"
108
-
with subtest("Check Radicale 2 functionality"):
110
-
"${switchToConfig "radicale2"} >&2"
112
-
radicale.wait_for_unit("radicale.service")
113
-
radicale.wait_for_open_port(${port})
115
-
(retcode, output) = radicale.execute(
116
-
"curl --fail http://${user}:${password}@localhost:${port}/someuser/calendar.ics/"
119
-
retcode == 0 and "VCALENDAR" in output
120
-
), "Could not read calendar from Radicale 2"
52
+
machine.wait_for_unit("radicale.service")
53
+
machine.wait_for_open_port(${port})
122
-
radicale.succeed("curl --fail http://${user}:${password}@localhost:${port}/.web/")
55
+
machine.succeed("sudo -u radicale git -C ${filesystem_folder} init")
57
+
"sudo -u radicale git -C ${filesystem_folder} config --local user.email radicale@example.com"
60
+
"sudo -u radicale git -C ${filesystem_folder} config --local user.name radicale"
124
-
with subtest("Check Radicale 3 functionality"):
126
-
"${switchToConfig "radicale3"} >&2"
128
-
radicale.wait_for_unit("radicale.service")
129
-
radicale.wait_for_open_port(${port})
63
+
with subtest("Test calendar and event creation"):
65
+
"${cli} --caldav-url http://localhost:${port}/${user} calendar create cal"
67
+
machine.succeed("test -d ${filesystem_folder}/collection-root/${user}/cal")
68
+
machine.succeed('test -z "$(ls ${filesystem_folder}/collection-root/${user}/cal)"')
70
+
"${cli} --caldav-url http://localhost:${port}/${user}/cal calendar add 2021-04-23 testevent"
72
+
machine.succeed('test -n "$(ls ${filesystem_folder}/collection-root/${user}/cal)"')
73
+
(status, stdout) = machine.execute(
74
+
"sudo -u radicale git -C ${filesystem_folder} log --format=oneline | wc -l"
76
+
assert status == 0, "git log failed"
77
+
assert stdout == "3\n", "there should be exactly 3 commits"
131
-
(retcode, output) = radicale.execute(
132
-
"curl --fail http://${user}:${password}@localhost:${port}/someuser/calendar.ics/"
135
-
retcode == 0 and "VCALENDAR" in output
136
-
), "Could not read calendar from Radicale 3"
79
+
with subtest("Test rights file"):
81
+
"${cli} --caldav-url http://localhost:${port}/${user} calendar create sub/cal"
84
+
"${cli} --caldav-url http://localhost:${port}/otheruser calendar create cal"
138
-
radicale.succeed("curl --fail http://${user}:${password}@localhost:${port}/.web/")
87
+
with subtest("Test web interface"):
88
+
machine.succeed("curl --fail http://${user}:${password}@localhost:${port}/.web/")