summary refs log tree commit diff
path: root/nixos/tests/postfix-raise-smtpd-tls-security-level.nix
blob: 5fad1fed75b2066a51c23a4f7c9b27b0c830b3dc (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
import ./make-test-python.nix {
  name = "postfix";

  machine = { pkgs, ... }: {
    imports = [ common/user-account.nix ];
    services.postfix = {
      enable = true;
      enableSubmissions = true;
      submissionsOptions = {
        smtpd_tls_security_level = "none";
      };
    };

    environment.systemPackages = let
      checkConfig = pkgs.writeScriptBin "check-config" ''
        #!${pkgs.python3.interpreter}
        import sys

        state = 1
        success = False

        with open("/etc/postfix/master.cf") as masterCf:
          for line in masterCf:
            if state == 1 and line.startswith("submissions"):
              state = 2
            elif state == 2 and line.startswith(" ") and "smtpd_tls_security_level=encrypt" in line:
              success = True
            elif state == 2 and not line.startswith(" "):
              state == 3
        if not success:
          sys.exit(1)
      '';

    in [ checkConfig ];
  };

  testScript = ''
    machine.wait_for_unit("postfix.service")
    machine.succeed("check-config")
  '';
}