2021-04-23 18:23:24 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ lib, pkgs, ... }:
|
|
|
|
|
2017-02-02 22:59:39 +00:00
|
|
|
let
|
2017-07-25 07:01:08 +00:00
|
|
|
user = "someuser";
|
|
|
|
password = "some_password";
|
2021-04-23 18:23:24 +00:00
|
|
|
port = "5232";
|
|
|
|
filesystem_folder = "/data/radicale";
|
|
|
|
|
2024-03-31 21:25:27 +00:00
|
|
|
cli = "${lib.getExe pkgs.calendar-cli} --caldav-user ${user} --caldav-pass ${password}";
|
2021-04-23 18:23:24 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "radicale3";
|
|
|
|
meta.maintainers = with lib.maintainers; [ dotlambda ];
|
2017-07-25 07:01:08 +00:00
|
|
|
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine =
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
2017-02-02 22:59:39 +00:00
|
|
|
services.radicale = {
|
|
|
|
enable = true;
|
2021-04-23 18:23:24 +00:00
|
|
|
settings = {
|
|
|
|
auth = {
|
|
|
|
type = "htpasswd";
|
|
|
|
htpasswd_filename = "/etc/radicale/users";
|
|
|
|
htpasswd_encryption = "bcrypt";
|
|
|
|
};
|
|
|
|
storage = {
|
|
|
|
inherit filesystem_folder;
|
|
|
|
hook = "git add -A && (git diff --cached --quiet || git commit -m 'Changes by '%(user)s)";
|
|
|
|
};
|
|
|
|
logging.level = "info";
|
|
|
|
};
|
|
|
|
rights = {
|
|
|
|
principal = {
|
|
|
|
user = ".+";
|
|
|
|
collection = "{user}";
|
|
|
|
permissions = "RW";
|
|
|
|
};
|
|
|
|
calendars = {
|
|
|
|
user = ".+";
|
|
|
|
collection = "{user}/[^/]+";
|
|
|
|
permissions = "rw";
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
|
|
|
};
|
2021-04-23 18:23:24 +00:00
|
|
|
};
|
|
|
|
systemd.services.radicale.path = [ pkgs.git ];
|
|
|
|
environment.systemPackages = [ pkgs.git ];
|
|
|
|
systemd.tmpfiles.rules = [ "d ${filesystem_folder} 0750 radicale radicale -" ];
|
2017-02-02 22:59:39 +00:00
|
|
|
# WARNING: DON'T DO THIS IN PRODUCTION!
|
2017-12-11 22:09:23 +00:00
|
|
|
# This puts unhashed secrets directly into the Nix store for ease of testing.
|
2021-04-23 18:23:24 +00:00
|
|
|
environment.etc."radicale/users".source = pkgs.runCommand "htpasswd" { } ''
|
2017-07-25 07:01:08 +00:00
|
|
|
${pkgs.apacheHttpd}/bin/htpasswd -bcB "$out" ${user} ${password}
|
2024-12-10 19:26:33 +00:00
|
|
|
'';
|
2021-04-23 18:23:24 +00:00
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_unit("radicale.service")
|
|
|
|
machine.wait_for_open_port(${port})
|
|
|
|
|
|
|
|
machine.succeed("sudo -u radicale git -C ${filesystem_folder} init")
|
|
|
|
machine.succeed(
|
|
|
|
"sudo -u radicale git -C ${filesystem_folder} config --local user.email radicale@example.com"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
"sudo -u radicale git -C ${filesystem_folder} config --local user.name radicale"
|
|
|
|
)
|
|
|
|
|
|
|
|
with subtest("Test calendar and event creation"):
|
|
|
|
machine.succeed(
|
|
|
|
"${cli} --caldav-url http://localhost:${port}/${user} calendar create cal"
|
|
|
|
)
|
|
|
|
machine.succeed("test -d ${filesystem_folder}/collection-root/${user}/cal")
|
|
|
|
machine.succeed('test -z "$(ls ${filesystem_folder}/collection-root/${user}/cal)"')
|
|
|
|
machine.succeed(
|
|
|
|
"${cli} --caldav-url http://localhost:${port}/${user}/cal calendar add 2021-04-23 testevent"
|
|
|
|
)
|
|
|
|
machine.succeed('test -n "$(ls ${filesystem_folder}/collection-root/${user}/cal)"')
|
|
|
|
(status, stdout) = machine.execute(
|
|
|
|
"sudo -u radicale git -C ${filesystem_folder} log --format=oneline | wc -l"
|
|
|
|
)
|
|
|
|
assert status == 0, "git log failed"
|
|
|
|
assert stdout == "3\n", "there should be exactly 3 commits"
|
|
|
|
|
|
|
|
with subtest("Test rights file"):
|
|
|
|
machine.fail(
|
|
|
|
"${cli} --caldav-url http://localhost:${port}/${user} calendar create sub/cal"
|
|
|
|
)
|
|
|
|
machine.fail(
|
|
|
|
"${cli} --caldav-url http://localhost:${port}/otheruser calendar create cal"
|
|
|
|
)
|
|
|
|
|
|
|
|
with subtest("Test web interface"):
|
|
|
|
machine.succeed("curl --fail http://${user}:${password}@localhost:${port}/.web/")
|
2021-05-03 16:52:55 +00:00
|
|
|
|
|
|
|
with subtest("Test security"):
|
|
|
|
output = machine.succeed("systemd-analyze security radicale.service")
|
|
|
|
machine.log(output)
|
|
|
|
assert output[-9:-1] == "SAFE :-}"
|
2021-04-23 18:23:24 +00:00
|
|
|
'';
|
2017-03-20 16:13:27 +00:00
|
|
|
}
|
|
|
|
)
|