···
1
+
# Rudimentary test checking that the Stalwart email server can:
2
+
# - receive some message through SMTP submission, then
3
+
# - serve this message through IMAP.
6
+
certs = import ./common/acme/server/snakeoil-certs.nix;
7
+
domain = certs.domain;
9
+
in import ./make-test-python.nix ({ lib, ... }: {
10
+
name = "stalwart-mail";
12
+
nodes.main = { pkgs, ... }: {
13
+
security.pki.certificateFiles = [ certs.ca.cert ];
15
+
services.stalwart-mail = {
18
+
server.hostname = domain;
20
+
certificate."snakeoil" = {
21
+
cert = "file://${certs.${domain}.cert}";
22
+
private-key = "file://${certs.${domain}.key}";
26
+
certificate = "snakeoil";
32
+
"smtp-submission" = {
33
+
bind = [ "[::]:587" ];
38
+
bind = [ "[::]:143" ];
43
+
session.auth.mechanisms = [ "PLAIN" ];
44
+
session.auth.directory = "in-memory";
45
+
jmap.directory = "in-memory"; # shared with imap
47
+
session.rcpt.directory = "in-memory";
48
+
queue.outbound.next-hop = [ "local" ];
50
+
directory."in-memory" = {
56
+
email = [ "alice@${domain}" ];
61
+
email = [ "bob@${domain}" ];
68
+
environment.systemPackages = [
69
+
(pkgs.writers.writePython3Bin "test-smtp-submission" { } ''
70
+
from smtplib import SMTP
72
+
with SMTP('localhost', 587) as smtp:
74
+
smtp.login('alice', 'foobar')
79
+
From: alice@${domain}
81
+
Subject: Some test message
83
+
This is a test message.
88
+
(pkgs.writers.writePython3Bin "test-imap-read" { } ''
89
+
from imaplib import IMAP4
91
+
with IMAP4('localhost') as imap:
93
+
imap.login('bob', 'foobar')
94
+
imap.select('"All Mail"')
95
+
status, [ref] = imap.search(None, 'ALL')
96
+
assert status == 'OK'
97
+
[msgId] = ref.split()
98
+
status, msg = imap.fetch(msgId, 'BODY[TEXT]')
99
+
assert status == 'OK'
100
+
assert msg[0][1].strip() == b'This is a test message.'
105
+
testScript = /* python */ ''
106
+
main.wait_for_unit("stalwart-mail.service")
107
+
main.wait_for_open_port(587)
108
+
main.wait_for_open_port(143)
110
+
main.succeed("test-smtp-submission")
111
+
main.succeed("test-imap-read")
115
+
maintainers = with lib.maintainers; [ happysalada pacien ];