aboutsummaryrefslogtreecommitdiffstats
path: root/tests/by-name/sn/snm-email-single-server/test.nix
blob: 7b5ec03f23ddb097325ca4237fc0daf8eaacd095 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{
  vhack,
  pkgs,
  vhackPackages,
  ...
}: let
  domain = "mail.server.test";

  common = import ../../../common/email/functions.nix {inherit pkgs vhackPackages;};
in
  vhack.runTest {
    name = "email";

    serverDomains = [
      {server = domain;}
    ];

    nodes = {
      server = {config, ...}: {
        systemd.tmpfiles.rules = [
          #-      path                   mode user group -           content
          "f     /passwords/alice        777  root root  -           alice-password"
          "f     /passwords/bob          777  root root  -           bob-password"
        ];

        # This DNS resolver is only there for rspamd (and apparently not even needed). But it
        # also removes our own name server changes, so the test node could no longer find
        # e.g. `acme.test` and so on.
        # See: https://gitlab.com/simple-nixos-mailserver/nixos-mailserver/-/work_items/100
        mailserver.localDnsResolver = false;

        vhack = {
          mail = {
            enable = true;
            fqdn = domain;
            domains = [
              domain
            ];
            accounts = {
              "alice@${domain}" = {
                passwordFile = "/passwords/alice";
              };
              "bob@${domain}" = {
                passwordFile = "/passwords/bob";
              };
            };
          };
        };
      };

      alice = common.mkUser "alice" domain;
      bob = common.mkUser "bob" domain;
    };

    services = [
      {server = "postfix.service";}
    ];

    ports = [
      {server = 993;} # imap
      {server = 465;} # smtp
    ];

    testScript = {...}:
    # Python
    ''
      with subtest("Both start without mail"):
        alice.succeed("sudo -u alice ${common.scripts.expectNoNewMail}")
        bob.succeed("sudo -u bob ${common.scripts.expectNoNewMail}")

      with subtest("Alice can send an email to bob"):
        alice.succeed("sudo -u alice ${pkgs.writeShellScript "alice-send" ''
        set -xe

        cat << EOF | msmtp --debug --account alice bob@${domain} >&2
        Hi Bob!

        This is an email.
        It contains a subject and a body.

        ALICE
        EOF
      ''}")
        bob.succeed("sudo -u bob ${common.scripts.expectNewMail}")
    '';
  }