From b849839d66c353c53548615d8e55c2397027aacb Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Wed, 28 Oct 2026 13:48:44 +0100 Subject: tests/simple-nixos-mailserver: Init These two tests kinda cover our email infrastructure. Importantly, all new mail gets classified as spam, which is why the tests do not really cover `rspamd`. As such things like dkim signing, correct DNS records and so on are not actually covered. --- tests/by-name/sn/snm-email-single-server/test.nix | 83 +++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/by-name/sn/snm-email-single-server/test.nix (limited to 'tests/by-name/sn/snm-email-single-server/test.nix') diff --git a/tests/by-name/sn/snm-email-single-server/test.nix b/tests/by-name/sn/snm-email-single-server/test.nix new file mode 100644 index 0000000..68c6022 --- /dev/null +++ b/tests/by-name/sn/snm-email-single-server/test.nix @@ -0,0 +1,83 @@ +{ + vhack, + pkgs, + vhackPackages, + ... +}: let + domain = "mail.server.test"; + + common = import ../../../common/email/functions.nix {inherit pkgs vhackPackages;}; +in + vhack.runTest { + name = "email"; + + serverDomains = [ + {server = domain;} + ]; + + nodes = { + server = {config, ...}: { + systemd.tmpfiles.rules = [ + #- path mode user group - content + "f /passwords/alice 777 root root - alice-password" + "f /passwords/bob 777 root root - bob-password" + ]; + + vhack = { + mail = { + enable = true; + fqdn = domain; + domains = [ + domain + ]; + accounts = { + "alice@${domain}" = { + passwordFile = "/passwords/alice"; + }; + "bob@${domain}" = { + passwordFile = "/passwords/bob"; + }; + }; + }; + }; + }; + + alice = common.mkUser "alice" domain; + bob = common.mkUser "bob" domain; + }; + + services = [ + {server = "postfix.service";} + ]; + + ports = [ + {server = 993;} # imap + {server = 465;} # smtp + ]; + + testScript = {...}: + # Python + '' + with subtest("Both start without mail"): + alice.succeed("sudo -u alice ${common.scripts.expectNoNewMail}") + bob.succeed("sudo -u bob ${common.scripts.expectNoNewMail}") + + with subtest("Alice can send an email to bob"): + alice.succeed("sudo -u alice ${pkgs.writeShellScript "alice-send" '' + set -xe + + cat << EOF | msmtp --debug --account alice bob@${domain} >&2 + Hi Bob! + + This is an email. + It contains a subject and a body. + + ALICE + EOF + ''}") + bob.succeed("sudo -u bob ${common.scripts.expectNewMail}") + + server.copy_from_machine("/var/lib/", "server") + bob.copy_from_machine("/home/bob/mail", "bob") + ''; + } -- cgit v1.3.1