Some checks failed
Test / tests (push) Failing after 3m0s
In order to simplify configuration and reduce configuration variability, this commit removes the option to directly add aliases to each single mail account. Instead, aliaes should be centrally configured using the option 'virtualAccountAliases'.
212 lines
8.2 KiB
Nix
212 lines
8.2 KiB
Nix
{pkgs, ...}:
|
|
with (import ./common/lib.nix {inherit pkgs;}); let
|
|
lib = pkgs.lib;
|
|
accounts = {
|
|
"normal" = {
|
|
address = "user1@example.com";
|
|
password = "secret-password1";
|
|
};
|
|
"normal2" = {
|
|
address = "user2@example.com";
|
|
password = "secret-password2;";
|
|
};
|
|
"alias" = {
|
|
address = "user3@example.com";
|
|
password = "secret-password3";
|
|
};
|
|
"multi-alias1" = {
|
|
address = "multi-alias1@example.com";
|
|
password = "secret-password4;";
|
|
};
|
|
"multi-alias2" = {
|
|
address = "multi-alias2@example.com";
|
|
password = "secret-password5;";
|
|
};
|
|
"catchall" = {
|
|
address = "catchall@example.com";
|
|
password = "secret-password6;";
|
|
};
|
|
"otherdomain" = {
|
|
address = "otherdomain@example.com";
|
|
password = "secret-password7;";
|
|
};
|
|
};
|
|
in
|
|
pkgs.nixosTest {
|
|
name = "aliases";
|
|
nodes = {
|
|
server = {pkgs, ...}: {
|
|
imports = [./common/server.nix];
|
|
environment.systemPackages = with pkgs; [netcat];
|
|
mailsystem = {
|
|
fqdn = "mail.example.com";
|
|
domains = ["example.com" "aliased.com" "otherdomain.com"];
|
|
accounts = mkAccounts accounts;
|
|
virtualDomainAliases = {
|
|
"aliased.com" = "example.com";
|
|
};
|
|
virtualAccountAliases = {
|
|
"alias@example.com" = accounts."alias".address;
|
|
"multi-alias@example.com" = lib.map (x: accounts.${x}.address) ["multi-alias1" "multi-alias2"];
|
|
"@example.com" = accounts."catchall".address;
|
|
"user@otherdomain.com" = accounts."otherdomain".address;
|
|
};
|
|
};
|
|
};
|
|
client = {...}: {
|
|
imports = [./common/client.nix];
|
|
};
|
|
};
|
|
testScript = {nodes, ...}: let
|
|
serverAddr = nodes.server.networking.primaryIPAddress;
|
|
clientAddr = nodes.client.networking.primaryIPAddress;
|
|
smtpSettings = {
|
|
address = serverAddr;
|
|
port = 465;
|
|
};
|
|
sendMail = mkSendMail smtpSettings accounts;
|
|
recvMail = mkRecvMail serverAddr accounts;
|
|
in ''
|
|
start_all()
|
|
|
|
server.wait_for_unit("multi-user.target")
|
|
client.wait_for_unit("multi-user.target")
|
|
server.wait_until_succeeds("${waitForRspamd nodes.server}")
|
|
|
|
with subtest("send mail from aliased address"):
|
|
client.succeed("${sendMail "alias" "alias@example.com" accounts."normal".address ''
|
|
Subject: Testmail1
|
|
|
|
Hello User1,
|
|
this is a mail dispatched using an alias instead of the normal address.
|
|
''}")
|
|
server.wait_until_fails('${pendingPostqueue}')
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
|
client.succeed("${recvMail "normal"} >&2")
|
|
|
|
with subtest("receive mail on aliased address"):
|
|
client.succeed("${sendMail "normal" "" "alias@example.com" ''
|
|
Subject: Testmail2
|
|
|
|
Hello alias-User,
|
|
this mail should reach you on your aliased address alias@example.com.
|
|
''}")
|
|
server.wait_until_fails('${pendingPostqueue}')
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
|
client.succeed("${recvMail "alias"} >&2")
|
|
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 1 when no new mail is available
|
|
# (as alias is the more specific address, catchall shouldn't receive the mail)
|
|
client.fail("${recvMail "catchall"} >&2")
|
|
|
|
with subtest("receive mail on all accounts with same alias"):
|
|
client.succeed("${sendMail "normal" "" "multi-alias@example.com" ''
|
|
Subject: Testmail3
|
|
|
|
Hello multi-alias-Users,
|
|
this mail should reach you on your aliased address multi-alias@example.com.
|
|
''}")
|
|
server.wait_until_fails('${pendingPostqueue}')
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
|
client.succeed("${recvMail "multi-alias1"} >&2")
|
|
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
|
client.succeed("${recvMail "multi-alias2"} >&2")
|
|
|
|
with subtest("send mail to catchAll-alias"):
|
|
# send email to non-existent account
|
|
client.succeed("${sendMail "normal" "" "somerandomaddress@example.com" ''
|
|
Subject: Catchall-Test
|
|
|
|
Hello Catchall-User,
|
|
this is mail is directed at an address with no explicit user-account behind it.
|
|
''}")
|
|
server.wait_until_fails('${pendingPostqueue}')
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
|
client.succeed("${recvMail "catchall"} >&2")
|
|
|
|
with subtest("send mail from catchAll-account with a non-existing account behind"):
|
|
# send email from non-existent account
|
|
client.succeed("${sendMail "catchall" "somerandomaddress@example.com" accounts."normal2".address ''
|
|
Subject: Catchall-Test2
|
|
|
|
Hello User2,
|
|
this is mail is sent from an address with no explicit user-account behind it.
|
|
''}")
|
|
server.wait_until_fails('${pendingPostqueue}')
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
|
client.succeed("${recvMail "normal2"} >&2")
|
|
|
|
with subtest("catchAll-account cannot send mail from an address with an existing account behind"):
|
|
# send email to non-existent account
|
|
client.fail("${sendMail "catchall" accounts."normal".address accounts."normal2".address ''
|
|
Subject: Catchall-Test3
|
|
|
|
Hello User2,
|
|
this is mail should not be possible to be sent as it is dispatched by a catchall-account using an address with a user-account behind it.
|
|
''}")
|
|
|
|
with subtest("send mail from aliased address of other domain"):
|
|
client.succeed("${sendMail "otherdomain" "user@otherdomain.com" accounts."normal".address ''
|
|
Subject: Dispatch from other domain
|
|
|
|
Hello User1,
|
|
this is a mail dispatched using an alias to a different domain instead of the normal address.
|
|
''}")
|
|
server.wait_until_fails('${pendingPostqueue}')
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
|
client.succeed("${recvMail "normal"} >&2")
|
|
|
|
with subtest("receive mail on aliased address of other domain"):
|
|
client.succeed("${sendMail "normal" "" "user@otherdomain.com" ''
|
|
Subject: Reception from other domain
|
|
|
|
Hello otherdomain-User,
|
|
this mail should reach you on your aliased address user@otherdomain.com.
|
|
''}")
|
|
server.wait_until_fails('${pendingPostqueue}')
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
|
client.succeed("${recvMail "otherdomain"} >&2")
|
|
|
|
with subtest("receiving mail on aliased domain using normal account"):
|
|
client.succeed("${sendMail "normal" "" "user2@aliased.com" ''
|
|
Subject: aliasedDomain with normal account
|
|
|
|
Hello User2,
|
|
this is mail is sent to you by using your address @example.org.
|
|
''}")
|
|
server.wait_until_fails('${pendingPostqueue}')
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
|
client.succeed("${recvMail "normal2"} >&2")
|
|
|
|
with subtest("receiving mail on aliased domain using catchall-account"):
|
|
client.succeed("${sendMail "normal" "" "somerandomaddress@aliased.com" ''
|
|
Subject: aliasedDomain using catchall-account
|
|
|
|
Hello Catchall-User,
|
|
this is mail is sent to you by using an address without any user-account behind it for neither @example.com nor @aliased.com.
|
|
''}")
|
|
server.wait_until_fails('${pendingPostqueue}')
|
|
client.execute("${cleanupMail}")
|
|
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
|
client.succeed("${recvMail "catchall"} >&2")
|
|
|
|
with subtest("sending mail from aliased domain fails"):
|
|
client.fail("${sendMail "normal" "user1@aliased.com" accounts."normal2".address ''
|
|
Subject: aliasedDomain
|
|
|
|
Hello User2,
|
|
this mail should not be dispatched to you as I'm using "my" address @aliased.com.
|
|
''}")
|
|
'';
|
|
}
|