nixos/tests/stalwart-mail: Add test for server version >= 0.7

(cherry picked from commit 4c626c52b7)
This commit is contained in:
Jonas Heinrich 2024-05-20 12:10:14 +02:00 committed by github-actions[bot]
parent f750e84bf1
commit d4b0f03904

View File

@ -1,25 +1,51 @@
# Rudimentary test checking that the Stalwart email server can:
# - receive some message through SMTP submission, then
# - serve this message through IMAP.
{
system ? builtins.currentSystem,
config ? { },
pkgs ? import ../../.. { inherit system config; },
lib ? pkgs.lib,
}:
let
certs = import ./common/acme/server/snakeoil-certs.nix;
domain = certs.domain;
makeTest = import ./make-test-python.nix;
mkTestName =
pkg: "${pkg.pname}_${pkg.version}";
stalwartPackages = {
inherit (pkgs) stalwart-mail_0_6 stalwart-mail;
};
stalwartAtLeast = lib.versionAtLeast;
makeStalwartTest =
{
package,
name ? mkTestName package,
}:
makeTest {
inherit name;
meta.maintainers = with lib.maintainers; [
happysalada pacien onny
];
in import ./make-test-python.nix ({ lib, ... }: {
name = "stalwart-mail";
nodes.machine = { lib, ... }: {
nodes.main = { pkgs, ... }: {
security.pki.certificateFiles = [ certs.ca.cert ];
services.stalwart-mail = {
enable = true;
inherit package;
settings = {
server.hostname = domain;
certificate."snakeoil" = {
cert = "file://${certs.${domain}.cert}";
private-key = "file://${certs.${domain}.key}";
# TODO: Remove backwards compatibility as soon as we drop legacy version 0.6.0
certificate."snakeoil" = let
certPath = if stalwartAtLeast package.version "0.7.0" then "%{file://${certs.${domain}.cert}}%" else "file://${certs.${domain}.cert}";
keyPath = if stalwartAtLeast package.version "0.7.0" then "%{file:${certs.${domain}.key}}%" else "file://${certs.${domain}.key}";
in {
cert = certPath;
private-key = keyPath;
};
server.tls = {
@ -40,8 +66,6 @@ in import ./make-test-python.nix ({ lib, ... }: {
};
};
resolver.public-suffix = [ ]; # do not fetch from web in sandbox
session.auth.mechanisms = "[plain]";
session.auth.directory = "'in-memory'";
storage.directory = "in-memory";
@ -51,15 +75,16 @@ in import ./make-test-python.nix ({ lib, ... }: {
directory."in-memory" = {
type = "memory";
principals = [
# TODO: Remove backwards compatibility as soon as we drop legacy version 0.6.0
principals = let
condition = if stalwartAtLeast package.version "0.7.0" then "class" else "type";
in builtins.map (p: p // { ${condition} = "individual"; }) [
{
type = "individual";
name = "alice";
secret = "foobar";
email = [ "alice@${domain}" ];
}
{
type = "individual";
name = "bob";
secret = "foobar";
email = [ "bob@${domain}" ];
@ -105,18 +130,18 @@ in import ./make-test-python.nix ({ lib, ... }: {
assert msg[0][1].strip() == b'This is a test message.'
'')
];
};
testScript = /* python */ ''
main.wait_for_unit("stalwart-mail.service")
main.wait_for_open_port(587)
main.wait_for_open_port(143)
testScript = ''
start_all()
machine.wait_for_unit("stalwart-mail.service")
machine.wait_for_open_port(587)
machine.wait_for_open_port(143)
main.succeed("test-smtp-submission")
main.succeed("test-imap-read")
machine.succeed("test-smtp-submission")
machine.succeed("test-imap-read")
'';
meta = {
maintainers = with lib.maintainers; [ happysalada pacien ];
};
})
in
lib.mapAttrs (_: package: makeStalwartTest { inherit package; }) stalwartPackages