1import ./make-test-python.nix (
2 { pkgs, ... }:
3 {
4 name = "ntfy-sh";
5
6 nodes.machine =
7 { ... }:
8 {
9 services.ntfy-sh.enable = true;
10 services.ntfy-sh.settings.base-url = "http://localhost:2586";
11
12 # Create a user with user:123
13 services.ntfy-sh.environmentFile = pkgs.writeText "ntfy.env" ''
14 NTFY_AUTH_DEFAULT_ACCESS='deny-all'
15 NTFY_AUTH_USERS='user:$2a$12$W2v7IQhkayvJOYRpg6YEruxj.jUO3R2xQOU7s1vC3HzLLB9gSKJ9.:user'
16 NTFY_AUTH_ACCESS='user:test:rw'
17 '';
18 };
19
20 testScript = ''
21 import json
22
23 msg = "Test notification"
24
25 machine.wait_for_unit("multi-user.target")
26
27 machine.wait_for_open_port(2586)
28
29 machine.succeed(f"curl -u user:1234 -d '{msg}' localhost:2586/test")
30
31 # If we have a user, receive a message
32 notif = json.loads(machine.succeed("curl -u user:1234 -s localhost:2586/test/json?poll=1"))
33 assert msg == notif["message"], "Wrong message"
34
35 # If we have no user, we should get forbidden, making sure the default access config works
36 notif = json.loads(machine.succeed("curl -s localhost:2586/test/json?poll=1"))
37 assert 403 == notif["http"], f"Should return 403, got {notif["http"]}"
38
39 machine.succeed("ntfy user list")
40 '';
41 }
42)