test/relay: init

Co-authored-by: Michael Lohmann <michael@lohmann.sh>
This commit is contained in:
Marcel 2025-01-08 09:46:39 +01:00
parent e4c6e6e2ee
commit 5648001ef3
No known key found for this signature in database
GPG Key ID: 446F3B093DF81C6A
2 changed files with 82 additions and 0 deletions

View File

@ -36,6 +36,7 @@
"internal"
"ldap"
"multiple"
"domainsWithoutMailbox"
];
genTest = testName: release: let

View File

@ -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"
)
'';
}