2025-05-24 23:40:23 +08:00
|
|
|
{ lib, ... }:
|
2025-04-03 06:49:33 +02:00
|
|
|
|
2025-05-24 23:40:23 +08:00
|
|
|
{
|
|
|
|
name = "pocket-id";
|
|
|
|
meta.maintainers = with lib.maintainers; [
|
|
|
|
gepbird
|
|
|
|
ymstnt
|
|
|
|
];
|
2025-04-03 06:49:33 +02:00
|
|
|
|
2025-05-24 23:40:23 +08:00
|
|
|
nodes = {
|
2025-08-17 08:55:21 +12:00
|
|
|
machineSqlite =
|
2025-05-24 23:40:23 +08:00
|
|
|
{ ... }:
|
|
|
|
{
|
|
|
|
services.pocket-id = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
PORT = 10001;
|
2025-04-03 06:49:33 +02:00
|
|
|
};
|
|
|
|
};
|
2025-05-24 23:40:23 +08:00
|
|
|
};
|
2025-08-17 08:55:21 +12:00
|
|
|
|
|
|
|
machinePostgres =
|
|
|
|
{ config, ... }:
|
|
|
|
let
|
|
|
|
username = config.services.pocket-id.user;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
services.pocket-id = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
PORT = 10001;
|
|
|
|
DB_PROVIDER = "postgres";
|
|
|
|
DB_CONNECTION_STRING = "host=/run/postgresql user=${username} database=${username}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = "${username}";
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
ensureDatabases = [ "${username}" ];
|
|
|
|
};
|
|
|
|
};
|
2025-05-24 23:40:23 +08:00
|
|
|
};
|
2025-04-03 06:49:33 +02:00
|
|
|
|
2025-05-24 23:40:23 +08:00
|
|
|
testScript =
|
|
|
|
{ nodes, ... }:
|
|
|
|
let
|
2025-08-17 08:55:21 +12:00
|
|
|
settingsSqlite = nodes.machineSqlite.services.pocket-id.settings;
|
|
|
|
settingsPostgres = nodes.machinePostgres.services.pocket-id.settings;
|
2025-05-24 23:40:23 +08:00
|
|
|
inherit (builtins) toString;
|
|
|
|
in
|
|
|
|
''
|
2025-08-17 08:55:21 +12:00
|
|
|
machineSqlite.wait_for_unit("pocket-id.service")
|
|
|
|
machineSqlite.wait_for_open_port(${toString settingsSqlite.PORT})
|
|
|
|
|
|
|
|
backend_status = machineSqlite.succeed("curl -L -o /tmp/backend-output -w '%{http_code}' http://localhost:${toString settingsSqlite.PORT}/api/users/me")
|
|
|
|
assert backend_status == "401"
|
|
|
|
machineSqlite.succeed("grep 'You are not signed in' /tmp/backend-output")
|
|
|
|
|
|
|
|
frontend_status = machineSqlite.succeed("curl -L -o /tmp/frontend-output -w '%{http_code}' http://localhost:${toString settingsSqlite.PORT}")
|
|
|
|
assert frontend_status == "200"
|
|
|
|
|
|
|
|
|
|
|
|
machinePostgres.wait_for_unit("pocket-id.service")
|
|
|
|
machinePostgres.wait_for_open_port(${toString settingsPostgres.PORT})
|
2025-04-03 06:49:33 +02:00
|
|
|
|
2025-08-17 08:55:21 +12:00
|
|
|
backend_status = machinePostgres.succeed("curl -L -o /tmp/backend-output -w '%{http_code}' http://localhost:${toString settingsPostgres.PORT}/api/users/me")
|
2025-05-24 23:40:23 +08:00
|
|
|
assert backend_status == "401"
|
2025-08-17 08:55:21 +12:00
|
|
|
machinePostgres.succeed("grep 'You are not signed in' /tmp/backend-output")
|
2025-04-03 06:49:33 +02:00
|
|
|
|
2025-08-17 08:55:21 +12:00
|
|
|
frontend_status = machinePostgres.succeed("curl -L -o /tmp/frontend-output -w '%{http_code}' http://localhost:${toString settingsPostgres.PORT}")
|
2025-05-24 23:40:23 +08:00
|
|
|
assert frontend_status == "200"
|
|
|
|
'';
|
|
|
|
}
|