blob: de6660052d679801fd732100d121c4cc15d198c8 (
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
|
# the ntfy-sh module was switching to DynamicUser=true. this test assures that
# the migration does not break existing setups.
#
# this test works doing a migration and asserting ntfy-sh runs properly. first,
# ntfy-sh is configured to use a static user and group. then ntfy-sh is
# started and tested. after that, ntfy-sh is shut down and a systemd drop
# in configuration file is used to upate the service configuration to use
# DynamicUser=true. then the ntfy-sh is started again and tested.
import ./make-test-python.nix {
name = "ntfy-sh";
nodes.machine = {
lib,
pkgs,
...
}: {
environment.etc."ntfy-sh-dynamic-user.conf".text = ''
[Service]
Group=new-ntfy-sh
User=new-ntfy-sh
DynamicUser=true
'';
services.ntfy-sh.enable = true;
services.ntfy-sh.settings.base-url = "http://localhost:2586";
systemd.services.ntfy-sh.serviceConfig = {
DynamicUser = lib.mkForce false;
ExecStartPre = [
"${pkgs.coreutils}/bin/id"
"${pkgs.coreutils}/bin/ls -lahd /var/lib/ntfy-sh/"
"${pkgs.coreutils}/bin/ls -lah /var/lib/ntfy-sh/"
];
Group = lib.mkForce "old-ntfy-sh";
User = lib.mkForce "old-ntfy-sh";
};
users.users.old-ntfy-sh = {
isSystemUser = true;
group = "old-ntfy-sh";
};
users.groups.old-ntfy-sh = {};
};
testScript = ''
import json
msg = "Test notification"
def test_ntfysh():
machine.wait_for_unit("ntfy-sh.service")
machine.wait_for_open_port(2586)
machine.succeed(f"curl -d '{msg}' localhost:2586/test")
text = machine.succeed("curl -s localhost:2586/test/json?poll=1")
for line in text.splitlines():
notif = json.loads(line)
assert msg == notif["message"], "Wrong message"
machine.succeed("ntfy user list")
machine.wait_for_unit("multi-user.target")
test_ntfysh()
machine.succeed("systemctl stop ntfy-sh.service")
machine.succeed("mkdir -p /run/systemd/system/ntfy-sh.service.d")
machine.succeed("cp /etc/ntfy-sh-dynamic-user.conf /run/systemd/system/ntfy-sh.service.d/dynamic-user.conf")
machine.succeed("systemctl daemon-reload")
machine.succeed("systemctl start ntfy-sh.service")
test_ntfysh()
'';
}
|