summaryrefslogtreecommitdiffstats
path: root/nixos/tests/postfix-tlspol.nix
blob: 76a99b920c757b537a8fccb5a6289c8e93e4de20 (plain)
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
{
  lib,
  ...
}:
{
  name = "postfix-tlspol";

  meta.maintainers = with lib.maintainers; [ hexa ];

  containers.machine = {
    services.postfix.enable = true;
    services.postfix-tlspol = {
      enable = true;
      settings.server.metrics-address = "127.0.0.1:8642";
    };

    services.dnsmasq = {
      enable = true;
      settings.selfmx = true;
    };
  };

  testScript = ''
    import json

    machine.wait_for_unit("postfix-tlspol.service")
    machine.succeed("getent group postfix-tlspol | grep :postfix")

    with subtest("Interact with the service"):
      machine.succeed("postfix-tlspol -purge")

      response = machine.log(machine.succeed("postfix-tlspol -query localhost"))
      response = json.loads(machine.succeed("postfix-tlspol -query localhost"))
      machine.log(json.dumps(response, indent=2))

      assert response["dane"]["policy"] == "", f"Unexpected DANE policy for localhost: {response["dane"]["policy"]}"
      assert response["mta-sts"]["policy"] == "TEMP", f"Unexpected MTA-STS policy for localhost: {response["mta-sts"]["policy"]}"

    with subtest("Metrics listener"):
      machine.log(machine.succeed("curl --silent --fail http://localhost:8642/metrics | grep --quiet postfix_tlspol_queries_total"))


    with subtest("Hardening"):
      machine.log(machine.execute("systemd-analyze security postfix-tlspol.service | grep -v ✓")[1])
  '';

}