at 23.11-pre 3.3 kB view raw
1import ./make-test-python.nix { 2 name = "mailman"; 3 4 nodes.machine = { pkgs, ... }: { 5 environment.systemPackages = with pkgs; [ mailutils ]; 6 7 services.mailman.enable = true; 8 services.mailman.serve.enable = true; 9 services.mailman.siteOwner = "postmaster@example.com"; 10 services.mailman.webHosts = [ "example.com" ]; 11 12 services.postfix.enable = true; 13 services.postfix.destination = [ "example.com" "example.net" ]; 14 services.postfix.relayDomains = [ "hash:/var/lib/mailman/data/postfix_domains" ]; 15 services.postfix.config.local_recipient_maps = [ "hash:/var/lib/mailman/data/postfix_lmtp" "proxy:unix:passwd.byname" ]; 16 services.postfix.config.transport_maps = [ "hash:/var/lib/mailman/data/postfix_lmtp" ]; 17 18 users.users.user = { isNormalUser = true; }; 19 20 virtualisation.memorySize = 2048; 21 22 specialisation.restApiPassFileSystem.configuration = { 23 services.mailman.restApiPassFile = "/var/lib/mailman/pass"; 24 }; 25 }; 26 27 testScript = { nodes, ... }: let 28 restApiPassFileSystem = "${nodes.machine.system.build.toplevel}/specialisation/restApiPassFileSystem"; 29 in '' 30 def check_mail(_) -> bool: 31 status, _ = machine.execute("grep -q hello /var/spool/mail/user/new/*") 32 return status == 0 33 34 def try_api(_) -> bool: 35 status, _ = machine.execute("curl -s http://localhost:8001/") 36 return status == 0 37 38 def wait_for_api(): 39 with machine.nested("waiting for Mailman REST API to be available"): 40 retry(try_api) 41 42 machine.wait_for_unit("mailman.service") 43 wait_for_api() 44 45 with subtest("subscription and delivery"): 46 creds = machine.succeed("su -s /bin/sh -c 'mailman info' mailman | grep '^REST credentials: ' | sed 's/^REST credentials: //'").strip() 47 machine.succeed(f"curl --fail-with-body -sLSu {creds} -d mail_host=example.com http://localhost:8001/3.1/domains") 48 machine.succeed(f"curl --fail-with-body -sLSu {creds} -d fqdn_listname=list@example.com http://localhost:8001/3.1/lists") 49 machine.succeed(f"curl --fail-with-body -sLSu {creds} -d list_id=list.example.com -d subscriber=root@example.com -d pre_confirmed=True -d pre_verified=True -d send_welcome_message=False http://localhost:8001/3.1/members") 50 machine.succeed(f"curl --fail-with-body -sLSu {creds} -d list_id=list.example.com -d subscriber=user@example.net -d pre_confirmed=True -d pre_verified=True -d send_welcome_message=False http://localhost:8001/3.1/members") 51 machine.succeed("mail -a 'From: root@example.com' -s hello list@example.com < /dev/null") 52 with machine.nested("waiting for mail from list"): 53 retry(check_mail) 54 55 with subtest("Postorius"): 56 machine.succeed("curl --fail-with-body -sILS http://localhost/") 57 58 with subtest("restApiPassFile"): 59 machine.succeed("echo secretpassword > /var/lib/mailman/pass") 60 machine.succeed("${restApiPassFileSystem}/bin/switch-to-configuration test >&2") 61 machine.succeed("grep secretpassword /etc/mailman.cfg") 62 machine.succeed("su -s /bin/sh -c 'mailman info' mailman | grep secretpassword") 63 wait_for_api() 64 machine.succeed("curl --fail-with-body -sLSu restadmin:secretpassword http://localhost:8001/3.1/domains") 65 machine.succeed("curl --fail-with-body -sILS http://localhost/") 66 ''; 67}