diff options
author | Antoine Eiche <lewo@abesis.fr> | 2020-09-28 20:51:32 +0200 |
---|---|---|
committer | Antoine Eiche <lewo@abesis.fr> | 2020-09-28 20:51:32 +0200 |
commit | c813f1205f0da413ec532cca868f57a57b7f8448 (patch) | |
tree | 0fccb230aeb3ce5b227740d037a2bac7caec0c60 /tests | |
parent | 24600377afa853cb31654b1987530bbf2f0add79 (diff) |
Add multiple.nix test
This test is used to test feature requiring several mail domains, such
as the `forwards` option.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/default.nix | 1 | ||||
-rw-r--r-- | tests/multiple.nix | 87 |
2 files changed, 88 insertions, 0 deletions
diff --git a/tests/default.nix b/tests/default.nix index 1e1b67b..e78a96f 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -35,6 +35,7 @@ let "intern" "extern" "clamav" + "multiple" ]; # Generate an attribute set containing one test per releases diff --git a/tests/multiple.nix b/tests/multiple.nix new file mode 100644 index 0000000..c6a4edf --- /dev/null +++ b/tests/multiple.nix @@ -0,0 +1,87 @@ +# This tests is used to test features requiring several mail domains. + +{ pkgs ? import <nixpkgs> {}}: + +let + hashPassword = password: pkgs.runCommand + "password-${password}-hashed" + { buildInputs = [ pkgs.mkpasswd ]; } + '' + mkpasswd -m sha-512 ${password} > $out + ''; + + password = pkgs.writeText "password" "password"; + + domainGenerator = domain: { config, pkgs, ... }: { + 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; + extraConfig = '' + mx-host=domain1.com,domain1,10 + mx-host=domain2.com,domain2,10 + ''; + }; + }; + +in + +pkgs.nixosTest { + name = "multiple"; + nodes = { + domain1 = {...}: { + imports = [ + ../default.nix + (domainGenerator "domain1.com") + ]; + mailserver.forwards = { + "non-local@domain1.com" = ["user@domain2.com" "user@domain1.com"]; + "non@domain1.com" = ["user@domain2.com" "user@domain1.com"]; + }; + }; + domain2 = domainGenerator "domain2.com"; + client = { config, 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") + + # TODO put this blocking into the systemd units? + domain1.wait_until_succeeds( + "timeout 1 ${pkgs.netcat}/bin/nc -U /run/rspamd/rspamd-milter.sock < /dev/null; [ $? -eq 124 ]" + ) + domain2.wait_until_succeeds( + "timeout 1 ${pkgs.netcat}/bin/nc -U /run/rspamd/rspamd-milter.sock < /dev/null; [ $? -eq 124 ]" + ) + + # user@domain1.com sends a mail to user@domain2.com + client.succeed( + "mail-check send-and-read --smtp-port 587 --smtp-starttls --smtp-host domain1 --from-addr user@domain1.com --imap-host domain2 --to-addr user@domain2.com --src-password-file ${password} --dst-password-file ${password} --ignore-dkim-spf" + ) + + # Send a mail to the address forwarded and check it is in the recipient mailbox + client.succeed( + "mail-check send-and-read --smtp-port 587 --smtp-starttls --smtp-host domain1 --from-addr user@domain1.com --imap-host domain2 --to-addr non-local@domain1.com --imap-username user@domain2.com --src-password-file ${password} --dst-password-file ${password} --ignore-dkim-spf" + ) + ''; +} |