From 5648001ef3c4ee4a82ecc30c3ec7eea804ce1a52 Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 8 Jan 2025 09:46:39 +0100 Subject: [PATCH] test/relay: init Co-authored-by: Michael Lohmann --- flake.nix | 1 + tests/domainsWithoutMailbox.nix | 81 +++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 tests/domainsWithoutMailbox.nix diff --git a/flake.nix b/flake.nix index 1581ea3..91bccc7 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,7 @@ "internal" "ldap" "multiple" + "domainsWithoutMailbox" ]; genTest = testName: release: let diff --git a/tests/domainsWithoutMailbox.nix b/tests/domainsWithoutMailbox.nix new file mode 100644 index 0000000..21bb52a --- /dev/null +++ b/tests/domainsWithoutMailbox.nix @@ -0,0 +1,81 @@ +# This tests is used to test features requiring several mail domains. + +{ pkgs, ... }: + +let + hashPassword = password: pkgs.runCommand + "password-${password}-hashed" + { buildInputs = [ pkgs.mkpasswd ]; inherit password; } + '' + mkpasswd -sm bcrypt <<<"$password" > $out + ''; + + password = pkgs.writeText "password" "password"; + + domainGenerator = domain: { + imports = [ ../default.nix ]; + virtualisation.memorySize = 1024; + mailserver = { + enable = true; + fqdn = "mail.${domain}"; + domains = [ domain ]; + localDnsResolver = false; + loginAccounts = { + "user@${domain}" = { + hashedPasswordFile = hashPassword "password"; + }; + }; + enableImap = true; + enableImapSsl = true; + }; + services = { + dnsmasq = { + enable = true; + settings.mx-host = [ "domain1.com,domain1,10" "domain2.com,domain2,10" ]; + }; + # disable rspamd graylisting and other stuff hardful top tests + rspamd.extraConfig = '' + actions { + reject = null; # Disable rejects, default is 15 + add_header = 6; # Add header when reaching this score + greylist = null; # Disable greylisting + } + ''; + }; + }; + +in + +{ + name = "domainsWithoutMailbox"; + nodes = { + domain1 = { + imports = [ + ../default.nix + (domainGenerator "domain1.com") + ]; + mailserver.domainsWithoutMailbox = [ "relay.domain1.com" ]; + # ip of itself + services.postfix.networks = [ "[2001:db8:1::1]/128" ]; + }; + domain2 = domainGenerator "domain2.com"; + client = { pkgs, ... }: { + environment.systemPackages = [ + (pkgs.writeScriptBin "mail-check" '' + ${pkgs.python3}/bin/python ${../scripts/mail-check.py} $@ + '') + ]; + }; + }; + testScript = '' + start_all() + + domain1.wait_for_unit("multi-user.target") + domain2.wait_for_unit("multi-user.target") + + # user@domain1.com sends a mail to user@domain2.com + client.succeed( + "mail-check send-and-read --smtp-port 25 --smtp-starttls --smtp-host domain1 --from-addr user@relay.domain1.com --imap-host domain2 --to-addr user@domain2.com --dst-password-file ${password} --ignore-dkim-spf" + ) + ''; +}