summary refs log tree commit diff
path: root/nixos/tests/radicale.nix
diff options
context:
space:
mode:
authorAneesh Agrawal <aneeshusa@gmail.com>2017-02-02 17:59:39 -0500
committerAneesh Agrawal <aneeshusa@gmail.com>2017-04-10 20:04:17 -0400
commit189479a4ba67fa935a1d407f4a4b87837fc53456 (patch)
treebc26786daed9dbc25a2d31a0bbce441f5190b031 /nixos/tests/radicale.nix
parent0168e48186bd5bbb5915bf3c591179cedd28802d (diff)
downloadnixlib-189479a4ba67fa935a1d407f4a4b87837fc53456.tar
nixlib-189479a4ba67fa935a1d407f4a4b87837fc53456.tar.gz
nixlib-189479a4ba67fa935a1d407f4a4b87837fc53456.tar.bz2
nixlib-189479a4ba67fa935a1d407f4a4b87837fc53456.tar.lz
nixlib-189479a4ba67fa935a1d407f4a4b87837fc53456.tar.xz
nixlib-189479a4ba67fa935a1d407f4a4b87837fc53456.tar.zst
nixlib-189479a4ba67fa935a1d407f4a4b87837fc53456.zip
radicale: Add NixOS test with Python 2
Includes testing bcrypt authentication.
Diffstat (limited to 'nixos/tests/radicale.nix')
-rw-r--r--nixos/tests/radicale.nix70
1 files changed, 70 insertions, 0 deletions
diff --git a/nixos/tests/radicale.nix b/nixos/tests/radicale.nix
new file mode 100644
index 000000000000..ea834d2768d2
--- /dev/null
+++ b/nixos/tests/radicale.nix
@@ -0,0 +1,70 @@
+let
+  port = 5232;
+  radicaleOverlay = self: super: {
+    radicale = super.radicale.overrideAttrs (oldAttrs: {
+      propagatedBuildInputs = with self.pythonPackages;
+        (oldAttrs.propagatedBuildInputs or []) ++ [
+          passlib
+        ];
+    });
+  };
+  common = { config, pkgs, ...}: {
+    services.radicale = {
+      enable = true;
+      config = let home = config.users.extraUsers.radicale.home; in ''
+        [server]
+        hosts = 127.0.0.1:${builtins.toString port}
+        daemon = False
+        [encoding]
+        [well-known]
+        [auth]
+        type = htpasswd
+        htpasswd_filename = /etc/radicale/htpasswd
+        htpasswd_encryption = bcrypt
+        [git]
+        [rights]
+        [storage]
+        type = filesystem
+        filesystem_folder = ${home}/collections
+        [logging]
+        [headers]
+      '';
+    };
+    # WARNING: DON'T DO THIS IN PRODUCTION!
+    # This puts secrets (albeit hashed) directly into the Nix store for ease of testing.
+    environment.etc."radicale/htpasswd".source = with pkgs; let
+      py = python.withPackages(ps: with ps; [ passlib ]);
+    in runCommand "htpasswd" {} ''
+        ${py}/bin/python -c "
+from passlib.apache import HtpasswdFile
+ht = HtpasswdFile(
+    '$out',
+    new=True,
+    default_scheme='bcrypt'
+)
+ht.set_password('someuser', 'really_secret_password')
+ht.save()
+"
+    '';
+  };
+
+in import ./make-test.nix {
+  name = "radicale";
+
+  # Test radicale with bcrypt-based htpasswd authentication
+  nodes = {
+    py2 = { config, pkgs, ... }@args: (common args) // {
+      nixpkgs.overlays = [
+        radicaleOverlay
+      ];
+    };
+  };
+
+  testScript = ''
+    for my $machine ($py2) {
+      $machine->waitForUnit('radicale.service');
+      $machine->waitForOpenPort(${builtins.toString port});
+      $machine->succeed('curl -s http://someuser:really_secret_password@127.0.0.1:${builtins.toString port}/someuser/calendar.ics/');
+    }
+  '';
+}