tests: Add various tests for alias functionality
This commit is contained in:
parent
457d91bcca
commit
92d0a6e1f8
2 changed files with 196 additions and 1 deletions
195
tests/aliases.nix
Normal file
195
tests/aliases.nix
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
{pkgs, ...}:
|
||||
with (import ./common/lib.nix {inherit pkgs;}); let
|
||||
accounts = {
|
||||
"normal" = {
|
||||
address = "user1@example.com";
|
||||
password = "secret-password1";
|
||||
};
|
||||
"normal2" = {
|
||||
address = "user2@example.com";
|
||||
password = "secret-password2;";
|
||||
};
|
||||
"alias" = {
|
||||
address = "user3@example.com";
|
||||
aliases = ["alias@example.com"];
|
||||
password = "secret-password3";
|
||||
};
|
||||
"extra-alias" = {
|
||||
address = "user4@example.com";
|
||||
password = "secret-password4;";
|
||||
};
|
||||
"multi-alias1" = {
|
||||
address = "multi-alias1@example.com";
|
||||
aliases = ["multi-alias@example.com"];
|
||||
password = "secret-password5;";
|
||||
};
|
||||
"multi-alias2" = {
|
||||
address = "multi-alias2@example.com";
|
||||
aliases = ["multi-alias@example.com"];
|
||||
password = "secret-password6;";
|
||||
};
|
||||
"catchall" = {
|
||||
address = "catchall@example.com";
|
||||
aliases = ["@example.com"];
|
||||
password = "secret-password7;";
|
||||
};
|
||||
"otherdomain" = {
|
||||
address = "otherdomain@example.com";
|
||||
aliases = ["user@otherdomain.com"];
|
||||
password = "secret-password8;";
|
||||
};
|
||||
};
|
||||
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" "otherdomain.com"];
|
||||
accounts = mkAccounts accounts;
|
||||
extraVirtualAliases = {
|
||||
"extra-alias@example.com" = accounts."extra-alias".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;
|
||||
cfg = nodes.server.mailsystem;
|
||||
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("mail incoming on extraVirtualAlias"):
|
||||
client.succeed("${sendMail "normal" "" "extra-alias@example.com" ''
|
||||
Subject: extraVirtualAliases-Test
|
||||
|
||||
Hello User4,
|
||||
this is mail is sent to you by using an extraVirtualAlias as recipient.
|
||||
''}")
|
||||
server.wait_until_fails('${pendingPostqueue}')
|
||||
client.execute("${cleanupMail}")
|
||||
# fetchmail returns EXIT_CODE 0 when it retrieves mail
|
||||
client.succeed("${recvMail "extra-alias"} >&2")
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue