1 import ../make-test-python.nix (
4 certs = import ../common/acme/server/snakeoil-certs.nix;
9 meta = with pkgs.lib.maintainers; {
10 maintainers = [ onny ];
20 primaryDomain = domain;
22 ensureAccounts = [ "postmaster@${domain}" ];
24 # Do not use this in production. This will make passwords world-readable
26 "postmaster@${domain}".passwordFile = "${pkgs.writeText "postmaster" "test"}";
32 certPath = "${certs.${domain}.cert}";
33 keyPath = "${certs.${domain}.key}";
37 # Enable TLS listeners. Configuring this via the module is not yet
40 builtins.replaceStrings
42 "imap tcp://0.0.0.0:143"
43 "submission tcp://0.0.0.0:587"
46 "imap tls://0.0.0.0:993 tcp://0.0.0.0:143"
47 "submission tls://0.0.0.0:465 tcp://0.0.0.0:587"
49 options.services.maddy.config.default;
51 # Not covered by openFirewall yet
52 networking.firewall.allowedTCPPorts = [
61 security.pki.certificateFiles = [
64 networking.extraHosts = ''
65 ${nodes.server.networking.primaryIPAddress} ${domain}
67 environment.systemPackages = [
68 (pkgs.writers.writePython3Bin "send-testmail" { } ''
71 from email.mime.text import MIMEText
73 context = ssl.create_default_context()
74 msg = MIMEText("Hello World")
75 msg['Subject'] = 'Test'
76 msg['From'] = "postmaster@${domain}"
77 msg['To'] = "postmaster@${domain}"
78 with smtplib.SMTP_SSL(host='${domain}', port=465, context=context) as smtp:
79 smtp.login('postmaster@${domain}', 'test')
81 'postmaster@${domain}', 'postmaster@${domain}', msg.as_string()
84 (pkgs.writers.writePython3Bin "test-imap" { } ''
87 with imaplib.IMAP4_SSL('${domain}') as imap:
88 imap.login('postmaster@${domain}', 'test')
90 status, refs = imap.search(None, 'ALL')
93 status, msg = imap.fetch(refs[0], 'BODY[TEXT]')
95 assert msg[0][1].strip() == b"Hello World"
103 server.wait_for_unit("maddy.service")
104 server.wait_for_open_port(143)
105 server.wait_for_open_port(993)
106 server.wait_for_open_port(587)
107 server.wait_for_open_port(465)
108 client.succeed("send-testmail")
109 client.succeed("test-imap")