1 import ./make-test-python.nix ({ lib, pkgs, ... }:
5 password = "some_password";
7 filesystem_folder = "/data/radicale";
9 cli = "${lib.getExe pkgs.calendar-cli} --caldav-user ${user} --caldav-pass ${password}";
12 meta.maintainers = with lib.maintainers; [ dotlambda ];
14 nodes.machine = { pkgs, ... }: {
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 -" ];
45 # WARNING: DON'T DO THIS IN PRODUCTION!
46 # This puts unhashed secrets directly into the Nix store for ease of testing.
47 environment.etc."radicale/users".source = pkgs.runCommand "htpasswd" {} ''
48 ${pkgs.apacheHttpd}/bin/htpasswd -bcB "$out" ${user} ${password}
52 machine.wait_for_unit("radicale.service")
53 machine.wait_for_open_port(${port})
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"
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"
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"
87 with subtest("Test web interface"):
88 machine.succeed("curl --fail http://${user}:${password}@localhost:${port}/.web/")
90 with subtest("Test security"):
91 output = machine.succeed("systemd-analyze security radicale.service")
93 assert output[-9:-1] == "SAFE :-}"