summaryrefslogtreecommitdiffstats
path: root/nixos/tests/cyrus-imap.nix
blob: 36145ed4748e42b9efff200ba93b532140929b09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{ lib, pkgs, ... }:
{
  name = "cyrus-imap";

  meta = {
    maintainers = with lib.maintainers; [ moraxyc ];
  };

  nodes.machine =
    { pkgs, ... }:
    {
      environment.systemPackages = with pkgs; [
        curl
        sudo
      ];
      services.saslauthd = {
        enable = true;
        config = ''
          DESC="SASL Authentication Daemon"
          NAME="saslauthd"
          MECH_OPTIONS=""
          THREADS=5
          START=yes
          OPTIONS="-c -m /run/saslauthd"
        '';
      };
      services.cyrus-imap = {
        enable = true;
        cyrusSettings = {
          START = {
            recover = {
              cmd = [
                "ctl_cyrusdb"
                "-r"
              ];
            };
          };
          EVENTS = {
            tlsprune = {
              cmd = [ "tls_prune" ];
              at = 400;
            };
            delprune = {
              cmd = [
                "cyr_expire"
                "-E"
                "3"
              ];
              at = 400;
            };
            deleteprune = {
              cmd = [
                "cyr_expire"
                "-E"
                "4"
                "-D"
                "28"
              ];
              at = 430;
            };
            expungeprune = {
              cmd = [
                "cyr_expire"
                "-E"
                "4"
                "-X"
                "28"
              ];
              at = 445;
            };
            checkpoint = {
              cmd = [
                "ctl_cyrusdb"
                "-c"
              ];
              period = 30;
            };
          };
          SERVICES = {
            http = {
              cmd = [ "httpd" ];
              listen = "80";
              prefork = 0;
            };
            imap = {
              cmd = [ "imapd" ];
              listen = "143";
              prefork = 0;
            };
            lmtpunix = {
              cmd = [ "lmtpd" ];
              listen = "/run/cyrus/lmtp";
              prefork = 0;
            };
            notify = {
              cmd = [ "notifyd" ];
              listen = "/run/cyrus/notify";
              proto = "udp";
              prefork = 0;
            };
          };
        };
      };
    };

  testScript = ''
    machine.wait_for_unit("saslauthd.service")
    machine.wait_for_unit("cyrus-imap.service")

    machine.wait_for_open_port(80)
    machine.wait_for_open_port(143)

    machine.succeed("echo 'secret' | ${lib.getExe' pkgs.cyrus_sasl.bin "saslpasswd2"} -p -c cyrus")
    machine.succeed("chown cyrus /etc/sasldb2")

    machine.succeed("sudo -ucyrus curl --fail --max-time 10 imap://cyrus:secret@localhost:143")
    machine.fail("curl --fail --max-time 10 imap://cyrus:wrongsecret@localhost:143")
    machine.fail("curl --fail --max-time 10 -X PROPFIND -H 'Depth: 1' 'http://localhost/dav/addressbooks/user/cyrus@localhost/Default'")
  '';
}