1{ lib, ... }:
2
3{
4 name = "pocket-id";
5 meta.maintainers = with lib.maintainers; [
6 gepbird
7 ymstnt
8 ];
9
10 nodes = {
11 machineSqlite =
12 { ... }:
13 {
14 services.pocket-id = {
15 enable = true;
16 settings = {
17 PORT = 10001;
18 };
19 };
20 };
21
22 machinePostgres =
23 { config, ... }:
24 let
25 username = config.services.pocket-id.user;
26 in
27 {
28 services.pocket-id = {
29 enable = true;
30 settings = {
31 PORT = 10001;
32 DB_PROVIDER = "postgres";
33 DB_CONNECTION_STRING = "host=/run/postgresql user=${username} database=${username}";
34 };
35 };
36
37 services.postgresql = {
38 enable = true;
39 ensureUsers = [
40 {
41 name = "${username}";
42 ensureDBOwnership = true;
43 }
44 ];
45 ensureDatabases = [ "${username}" ];
46 };
47 };
48 };
49
50 testScript =
51 { nodes, ... }:
52 let
53 settingsSqlite = nodes.machineSqlite.services.pocket-id.settings;
54 settingsPostgres = nodes.machinePostgres.services.pocket-id.settings;
55 inherit (builtins) toString;
56 in
57 ''
58 machineSqlite.wait_for_unit("pocket-id.service")
59 machineSqlite.wait_for_open_port(${toString settingsSqlite.PORT})
60
61 backend_status = machineSqlite.succeed("curl -L -o /tmp/backend-output -w '%{http_code}' http://localhost:${toString settingsSqlite.PORT}/api/users/me")
62 assert backend_status == "401"
63 machineSqlite.succeed("grep 'You are not signed in' /tmp/backend-output")
64
65 frontend_status = machineSqlite.succeed("curl -L -o /tmp/frontend-output -w '%{http_code}' http://localhost:${toString settingsSqlite.PORT}")
66 assert frontend_status == "200"
67
68
69 machinePostgres.wait_for_unit("pocket-id.service")
70 machinePostgres.wait_for_open_port(${toString settingsPostgres.PORT})
71
72 backend_status = machinePostgres.succeed("curl -L -o /tmp/backend-output -w '%{http_code}' http://localhost:${toString settingsPostgres.PORT}/api/users/me")
73 assert backend_status == "401"
74 machinePostgres.succeed("grep 'You are not signed in' /tmp/backend-output")
75
76 frontend_status = machinePostgres.succeed("curl -L -o /tmp/frontend-output -w '%{http_code}' http://localhost:${toString settingsPostgres.PORT}")
77 assert frontend_status == "200"
78 '';
79}