mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 23:43:30 +00:00
653f805f09
This plugin is used commonly enough that we should ensure it still builds (and dovecot works) after loading it. This is not yet perfect as we aren't testing any of it's functionality but at least we ensure that dovecot continues to do the regular job.
81 lines
2.3 KiB
Nix
81 lines
2.3 KiB
Nix
import ./make-test-python.nix {
|
|
name = "dovecot";
|
|
|
|
machine = { pkgs, ... }: {
|
|
imports = [ common/user-account.nix ];
|
|
services.postfix.enable = true;
|
|
services.dovecot2 = {
|
|
enable = true;
|
|
protocols = [ "imap" "pop3" ];
|
|
modules = [ pkgs.dovecot_pigeonhole ];
|
|
};
|
|
environment.systemPackages = let
|
|
sendTestMail = pkgs.writeScriptBin "send-testmail" ''
|
|
#!${pkgs.runtimeShell}
|
|
exec sendmail -vt <<MAIL
|
|
From: root@localhost
|
|
To: alice@localhost
|
|
Subject: Very important!
|
|
|
|
Hello world!
|
|
MAIL
|
|
'';
|
|
|
|
sendTestMailViaDeliveryAgent = pkgs.writeScriptBin "send-lda" ''
|
|
#!${pkgs.runtimeShell}
|
|
|
|
exec ${pkgs.dovecot}/libexec/dovecot/deliver -d bob <<MAIL
|
|
From: root@localhost
|
|
To: bob@localhost
|
|
Subject: Something else...
|
|
|
|
I'm running short of ideas!
|
|
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('bob')
|
|
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"I'm running short of ideas!"
|
|
finally:
|
|
pop.quit()
|
|
'';
|
|
|
|
in [ sendTestMail sendTestMailViaDeliveryAgent testImap testPop ];
|
|
};
|
|
|
|
testScript = ''
|
|
machine.wait_for_unit("postfix.service")
|
|
machine.wait_for_unit("dovecot2.service")
|
|
machine.succeed("send-testmail")
|
|
machine.succeed("send-lda")
|
|
machine.wait_until_fails('[ "$(postqueue -p)" != "Mail queue is empty" ]')
|
|
machine.succeed("test-imap")
|
|
machine.succeed("test-pop")
|
|
'';
|
|
}
|