diff options
author | Jonas Heinrich <onny@project-insanity.org> | 2021-09-10 13:08:58 +0200 |
---|---|---|
committer | Patrick Hilhorst <git@hilhorst.be> | 2021-12-07 22:58:22 +0100 |
commit | ecd88f91a0aa5a25e2cd44a1a09e404bea53d458 (patch) | |
tree | bdb62f89e6535994b2d862c9f03b6754bcbb095b /nixos/tests/maddy.nix | |
parent | 61123a6453c38fe5a279fbfd11a7f5046b3a32bd (diff) |
nixos/maddy: Add module for maddy
Co-authored-by: Patrick Hilhorst <git@hilhorst.be>
Diffstat (limited to 'nixos/tests/maddy.nix')
-rw-r--r-- | nixos/tests/maddy.nix | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/nixos/tests/maddy.nix b/nixos/tests/maddy.nix new file mode 100644 index 0000000000000..581748c1fa59b --- /dev/null +++ b/nixos/tests/maddy.nix @@ -0,0 +1,58 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "maddy"; + meta = with pkgs.lib.maintainers; { maintainers = [ onny ]; }; + + nodes = { + server = { ... }: { + services.maddy = { + enable = true; + hostname = "server"; + primaryDomain = "server"; + openFirewall = true; + }; + }; + + client = { ... }: { + environment.systemPackages = [ + (pkgs.writers.writePython3Bin "send-testmail" { } '' + import smtplib + from email.mime.text import MIMEText + + msg = MIMEText("Hello World") + msg['Subject'] = 'Test' + msg['From'] = "postmaster@server" + msg['To'] = "postmaster@server" + with smtplib.SMTP('server', 587) as smtp: + smtp.login('postmaster@server', 'test') + smtp.sendmail('postmaster@server', 'postmaster@server', msg.as_string()) + '') + (pkgs.writers.writePython3Bin "test-imap" { } '' + import imaplib + + with imaplib.IMAP4('server') as imap: + imap.login('postmaster@server', 'test') + 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" + '') + ]; + }; + }; + + testScript = '' + start_all() + server.wait_for_unit("maddy.service") + server.wait_for_open_port(143) + server.wait_for_open_port(587) + + server.succeed("echo test | maddyctl creds create postmaster@server") + server.succeed("maddyctl imap-acct create postmaster@server") + + client.succeed("send-testmail") + client.succeed("test-imap") + ''; +}) |