1 # the ntfy-sh module was switching to DynamicUser=true. this test assures that
2 # the migration does not break existing setups.
4 # this test works doing a migration and asserting ntfy-sh runs properly. first,
5 # ntfy-sh is configured to use a static user and group. then ntfy-sh is
6 # started and tested. after that, ntfy-sh is shut down and a systemd drop
7 # in configuration file is used to upate the service configuration to use
8 # DynamicUser=true. then the ntfy-sh is started again and tested.
10 import ./make-test-python.nix {
18 environment.etc."ntfy-sh-dynamic-user.conf".text = ''
25 services.ntfy-sh.enable = true;
26 services.ntfy-sh.settings.base-url = "http://localhost:2586";
28 systemd.services.ntfy-sh.serviceConfig = {
29 DynamicUser = lib.mkForce false;
31 "${pkgs.coreutils}/bin/id"
32 "${pkgs.coreutils}/bin/ls -lahd /var/lib/ntfy-sh/"
33 "${pkgs.coreutils}/bin/ls -lah /var/lib/ntfy-sh/"
35 Group = lib.mkForce "old-ntfy-sh";
36 User = lib.mkForce "old-ntfy-sh";
39 users.users.old-ntfy-sh = {
41 group = "old-ntfy-sh";
44 users.groups.old-ntfy-sh = {};
50 msg = "Test notification"
53 machine.wait_for_unit("ntfy-sh.service")
54 machine.wait_for_open_port(2586)
56 machine.succeed(f"curl -d '{msg}' localhost:2586/test")
58 text = machine.succeed("curl -s localhost:2586/test/json?poll=1")
59 for line in text.splitlines():
60 notif = json.loads(line)
61 assert msg == notif["message"], "Wrong message"
63 machine.succeed("ntfy user list")
65 machine.wait_for_unit("multi-user.target")
69 machine.succeed("systemctl stop ntfy-sh.service")
70 machine.succeed("mkdir -p /run/systemd/system/ntfy-sh.service.d")
71 machine.succeed("cp /etc/ntfy-sh-dynamic-user.conf /run/systemd/system/ntfy-sh.service.d/dynamic-user.conf")
72 machine.succeed("systemctl daemon-reload")
73 machine.succeed("systemctl start ntfy-sh.service")