summary refs log tree commit diff
path: root/nixos/tests/dovecot.nix
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2017-09-17 03:11:01 +0200
committeraszlig <aszlig@redmoonstudios.org>2017-09-17 04:57:20 +0200
commit3ba2095a42af1caa2b9a22cd2d3a0b24f72ccda8 (patch)
tree68b60d5042c77acd2a4113d61b5c1324361bc5df /nixos/tests/dovecot.nix
parent222e18698a5a6b92085d7ed1b307e74878a00c8e (diff)
downloadnixlib-3ba2095a42af1caa2b9a22cd2d3a0b24f72ccda8.tar
nixlib-3ba2095a42af1caa2b9a22cd2d3a0b24f72ccda8.tar.gz
nixlib-3ba2095a42af1caa2b9a22cd2d3a0b24f72ccda8.tar.bz2
nixlib-3ba2095a42af1caa2b9a22cd2d3a0b24f72ccda8.tar.lz
nixlib-3ba2095a42af1caa2b9a22cd2d3a0b24f72ccda8.tar.xz
nixlib-3ba2095a42af1caa2b9a22cd2d3a0b24f72ccda8.tar.zst
nixlib-3ba2095a42af1caa2b9a22cd2d3a0b24f72ccda8.zip
nixos/dovecot: Fix createMailUser implementation
This option got introduced in 7904499542814b8a4d04fce8dc7ca8c383c083e7
and it didn't check whether mailUser and mailGroup are null, which they
are by default.

Now we're only creating the user if createMailUser is set in conjunction
with mailUser and the group if mailGroup is set as well.

I've added a NixOS VM test so that we can verify whether dovecot works
without any additional options set, so it serves as a regression test
for issue #29466 and other issues that might come up with future changes
to the Dovecot service.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Fixes: #29466
Cc: @qknight, @abbradar, @ixmatus, @siddharthist
Diffstat (limited to 'nixos/tests/dovecot.nix')
-rw-r--r--nixos/tests/dovecot.nix64
1 files changed, 64 insertions, 0 deletions
diff --git a/nixos/tests/dovecot.nix b/nixos/tests/dovecot.nix
new file mode 100644
index 000000000000..3814855ed8e7
--- /dev/null
+++ b/nixos/tests/dovecot.nix
@@ -0,0 +1,64 @@
+import ./make-test.nix {
+  name = "dovecot";
+
+  machine = { pkgs, ... }: {
+    imports = [ common/user-account.nix ];
+    services.postfix.enable = true;
+    services.dovecot2.enable = true;
+    services.dovecot2.protocols = [ "imap" "pop3" ];
+    environment.systemPackages = let
+      sendTestMail = pkgs.writeScriptBin "send-testmail" ''
+        #!${pkgs.stdenv.shell}
+        exec sendmail -vt <<MAIL
+        From: root@localhost
+        To: alice@localhost
+        Subject: Very important!
+
+        Hello world!
+        MAIL
+      '';
+
+      testImap = pkgs.writeScriptBin "test-imap" ''
+        #!${pkgs.python3.interpreter}
+        import imaplib
+
+        with imaplib.IMAP4('localhost') as imap:
+          imap.login('alice', 'foobar')
+          imap.select()
+          status, refs = imap.search(None, 'ALL')
+          assert status == 'OK'
+          assert len(refs) == 1
+          status, msg = imap.fetch(refs[0], 'BODY[TEXT]')
+          assert status == 'OK'
+          assert msg[0][1].strip() == b'Hello world!'
+      '';
+
+      testPop = pkgs.writeScriptBin "test-pop" ''
+        #!${pkgs.python3.interpreter}
+        import poplib
+
+        pop = poplib.POP3('localhost')
+        try:
+          pop.user('alice')
+          pop.pass_('foobar')
+          assert len(pop.list()[1]) == 1
+          status, fullmail, size = pop.retr(1)
+          assert status.startswith(b'+OK ')
+          body = b"".join(fullmail[fullmail.index(b""):]).strip()
+          assert body == b'Hello world!'
+        finally:
+          pop.quit()
+      '';
+
+    in [ sendTestMail testImap testPop ];
+  };
+
+  testScript = ''
+    $machine->waitForUnit('postfix.service');
+    $machine->waitForUnit('dovecot2.service');
+    $machine->succeed('send-testmail');
+    $machine->waitUntilFails('[ "$(postqueue -p)" != "Mail queue is empty" ]');
+    $machine->succeed('test-imap');
+    $machine->succeed('test-pop');
+  '';
+}