1 import ../make-test-python.nix ({ pkgs, ... }:
3 certs = import ../common/acme/server/snakeoil-certs.nix;
7 meta = with pkgs.lib.maintainers; { maintainers = [ onny ]; };
10 server = { options, ... }: {
14 primaryDomain = domain;
16 ensureAccounts = [ "postmaster@${domain}" ];
18 # Do not use this in production. This will make passwords world-readable
20 "postmaster@${domain}".passwordFile = "${pkgs.writeText "postmaster" "test"}";
25 certPath = "${certs.${domain}.cert}";
26 keyPath = "${certs.${domain}.key}";
29 # Enable TLS listeners. Configuring this via the module is not yet
31 config = builtins.replaceStrings [
32 "imap tcp://0.0.0.0:143"
33 "submission tcp://0.0.0.0:587"
35 "imap tls://0.0.0.0:993 tcp://0.0.0.0:143"
36 "submission tls://0.0.0.0:465 tcp://0.0.0.0:587"
37 ] options.services.maddy.config.default;
39 # Not covered by openFirewall yet
40 networking.firewall.allowedTCPPorts = [ 993 465 ];
43 client = { nodes, ... }: {
44 security.pki.certificateFiles = [
47 networking.extraHosts = ''
48 ${nodes.server.networking.primaryIPAddress} ${domain}
50 environment.systemPackages = [
51 (pkgs.writers.writePython3Bin "send-testmail" { } ''
54 from email.mime.text import MIMEText
56 context = ssl.create_default_context()
57 msg = MIMEText("Hello World")
58 msg['Subject'] = 'Test'
59 msg['From'] = "postmaster@${domain}"
60 msg['To'] = "postmaster@${domain}"
61 with smtplib.SMTP_SSL(host='${domain}', port=465, context=context) as smtp:
62 smtp.login('postmaster@${domain}', 'test')
64 'postmaster@${domain}', 'postmaster@${domain}', msg.as_string()
67 (pkgs.writers.writePython3Bin "test-imap" { } ''
70 with imaplib.IMAP4_SSL('${domain}') as imap:
71 imap.login('postmaster@${domain}', 'test')
73 status, refs = imap.search(None, 'ALL')
76 status, msg = imap.fetch(refs[0], 'BODY[TEXT]')
78 assert msg[0][1].strip() == b"Hello World"
86 server.wait_for_unit("maddy.service")
87 server.wait_for_open_port(143)
88 server.wait_for_open_port(993)
89 server.wait_for_open_port(587)
90 server.wait_for_open_port(465)
91 client.succeed("send-testmail")
92 client.succeed("test-imap")