···
+
# Rudimentary test checking that the Stalwart email server can:
+
# - receive some message through SMTP submission, then
+
# - serve this message through IMAP.
+
certs = import ./common/acme/server/snakeoil-certs.nix;
+
in import ./make-test-python.nix ({ lib, ... }: {
+
name = "stalwart-mail";
+
nodes.main = { pkgs, ... }: {
+
security.pki.certificateFiles = [ certs.ca.cert ];
+
services.stalwart-mail = {
+
server.hostname = domain;
+
certificate."snakeoil" = {
+
cert = "file://${certs.${domain}.cert}";
+
private-key = "file://${certs.${domain}.key}";
+
certificate = "snakeoil";
+
session.auth.mechanisms = [ "PLAIN" ];
+
session.auth.directory = "in-memory";
+
jmap.directory = "in-memory"; # shared with imap
+
session.rcpt.directory = "in-memory";
+
queue.outbound.next-hop = [ "local" ];
+
directory."in-memory" = {
+
email = [ "alice@${domain}" ];
+
email = [ "bob@${domain}" ];
+
environment.systemPackages = [
+
(pkgs.writers.writePython3Bin "test-smtp-submission" { } ''
+
from smtplib import SMTP
+
with SMTP('localhost', 587) as smtp:
+
smtp.login('alice', 'foobar')
+
Subject: Some test message
+
This is a test message.
+
(pkgs.writers.writePython3Bin "test-imap-read" { } ''
+
from imaplib import IMAP4
+
with IMAP4('localhost') as imap:
+
imap.login('bob', 'foobar')
+
imap.select('"All Mail"')
+
status, [ref] = imap.search(None, 'ALL')
+
status, msg = imap.fetch(msgId, 'BODY[TEXT]')
+
assert msg[0][1].strip() == b'This is a test message.'
+
testScript = /* python */ ''
+
main.wait_for_unit("stalwart-mail.service")
+
main.wait_for_open_port(587)
+
main.wait_for_open_port(143)
+
main.succeed("test-smtp-submission")
+
main.succeed("test-imap-read")
+
maintainers = with lib.maintainers; [ happysalada pacien ];