@podosoft/podokit 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/deploy-compose-profile.js +2 -2
  2. package/dist/deploy-compose-render.js +3 -1
  3. package/dist/deploy-profile.js +2 -2
  4. package/dist/deploy-render.js +16 -8
  5. package/dist/deploy-schema.d.ts +7 -0
  6. package/dist/deploy-schema.js +40 -0
  7. package/dist/lockfile.d.ts +8 -1
  8. package/dist/lockfile.js +23 -4
  9. package/dist/provider.d.ts +1 -0
  10. package/dist/provider.js +5 -2
  11. package/dist/templates/fullstack/AGENTS.md +27 -2
  12. package/dist/templates/fullstack/README.md +1 -1
  13. package/dist/templates/fullstack/apps/api/package.json +1 -1
  14. package/dist/templates/fullstack/apps/api/scripts/run-migrations.mjs +4 -0
  15. package/dist/templates/fullstack/apps/api/src/app.extensions.ts +7 -2
  16. package/dist/templates/fullstack/apps/api/src/app.ts +6 -3
  17. package/dist/templates/fullstack/apps/api/src/config/env.validation.ts +28 -0
  18. package/dist/templates/fullstack/apps/api/src/config/providers.ts +4 -2
  19. package/dist/templates/fullstack/apps/api/src/config/server-options.spec.ts +17 -6
  20. package/dist/templates/fullstack/apps/api/src/config/server-options.ts +5 -8
  21. package/dist/templates/fullstack/apps/api/src/core/client-address.spec.ts +82 -0
  22. package/dist/templates/fullstack/apps/api/src/core/client-address.ts +68 -0
  23. package/dist/templates/fullstack/apps/api/src/core/services.ts +30 -0
  24. package/dist/templates/fullstack/apps/api/src/database/database.spec.ts +66 -0
  25. package/dist/templates/fullstack/apps/api/src/database/database.ts +34 -11
  26. package/dist/templates/fullstack/apps/api/src/database/run-migrations.spec.ts +54 -6
  27. package/dist/templates/fullstack/apps/web/Dockerfile +5 -1
  28. package/dist/templates/fullstack/apps/web/src/lib/server/api.test.ts +116 -0
  29. package/dist/templates/fullstack/apps/web/src/lib/server/api.ts +34 -4
  30. package/dist/templates/fullstack/apps/web/src/lib/server/backend-proxy.test.ts +436 -6
  31. package/dist/templates/fullstack/apps/web/src/lib/server/backend-proxy.ts +352 -38
  32. package/dist/templates/fullstack/apps/web/src/lib/server/body-limits.ts +5 -2
  33. package/dist/templates/fullstack/apps/web/src/lib/server/proxy-timeouts.ts +22 -0
  34. package/dist/templates/fullstack/apps/web/src/routes/healthz/+server.ts +13 -0
  35. package/dist/templates/fullstack/dot-env.docker.example +6 -0
  36. package/dist/templates/fullstack/dot-env.example +23 -0
  37. package/dist/templates/fullstack/infra/k3s/configmap.yaml +3 -0
  38. package/dist/templates/fullstack/infra/k3s/web-deployment.yaml +6 -3
  39. package/dist/templates/fullstack/tests/api/health.api.spec.ts +8 -0
  40. package/dist/templates/modules/admin-dashboard/files/apps/api/src/account-sessions/account-sessions.routes.spec.ts +152 -0
  41. package/dist/templates/modules/admin-dashboard/files/apps/api/src/account-sessions/account-sessions.routes.ts +112 -0
  42. package/dist/templates/modules/admin-dashboard/files/apps/api/src/admin-sessions/admin-sessions.revoker.ts +24 -0
  43. package/dist/templates/modules/admin-dashboard/files/apps/api/src/admin-sessions/admin-sessions.service.spec.ts +18 -0
  44. package/dist/templates/modules/admin-dashboard/files/apps/api/src/admin-sessions/admin-sessions.service.ts +36 -13
  45. package/dist/templates/modules/admin-dashboard/files/apps/api/src/admin.module.ts +13 -1
  46. package/dist/templates/modules/admin-dashboard/files/apps/web/src/hooks.server.test.ts +24 -1
  47. package/dist/templates/modules/admin-dashboard/files/apps/web/src/lib/account-sessions.test.ts +33 -0
  48. package/dist/templates/modules/admin-dashboard/files/apps/web/src/lib/account-sessions.ts +34 -0
  49. package/dist/templates/modules/admin-dashboard/files/apps/web/src/lib/components/account-page.svelte +62 -38
  50. package/dist/templates/modules/admin-dashboard/files/apps/web/src/lib/components/table-toolbar.svelte +3 -1
  51. package/dist/templates/modules/admin-dashboard/files/apps/web/src/lib/server/runtime-context.test.ts +6 -0
  52. package/dist/templates/modules/admin-dashboard/files/apps/web/src/lib/server/runtime-context.ts +5 -0
  53. package/dist/templates/modules/admin-dashboard/files/tests/api/account-sessions.api.spec.ts +55 -0
  54. package/dist/templates/modules/admin-dashboard/files/tests/api/auth-config.api.spec.ts +167 -154
  55. package/dist/templates/modules/admin-dashboard/files/tests/api/auth.api.spec.ts +94 -57
  56. package/dist/templates/modules/admin-dashboard/files/tests/api/exclusive.api.spec.ts +75 -0
  57. package/dist/templates/modules/admin-dashboard/files/tests/api/site-settings.api.spec.ts +49 -39
  58. package/dist/templates/modules/admin-dashboard/files/tests/api/users-admin.api.spec.ts +26 -0
  59. package/dist/templates/modules/admin-dashboard/files/tests/helpers/devices.ts +25 -0
  60. package/dist/templates/modules/admin-dashboard/files/tests/helpers/exclusive.ts +80 -0
  61. package/dist/templates/modules/admin-dashboard/files/tests/seed.setup.ts +3 -10
  62. package/dist/templates/modules/admin-dashboard/files/tests/ui/account-sessions.ui.spec.ts +46 -0
  63. package/dist/templates/modules/admin-dashboard/files/tests/ui/account.ui.spec.ts +54 -47
  64. package/dist/templates/modules/admin-dashboard/files/tests/ui/appearance.ui.spec.ts +15 -11
  65. package/dist/templates/modules/admin-dashboard/files/tests/ui/auth.ui.spec.ts +35 -31
  66. package/dist/templates/modules/admin-dashboard/files/tests/ui/general-effects.ui.spec.ts +90 -76
  67. package/dist/templates/modules/admin-dashboard/files/tests/ui/i18n.ui.spec.ts +19 -15
  68. package/dist/templates/modules/admin-dashboard/files/tests/ui/oidc.ui.spec.ts +17 -3
  69. package/dist/templates/modules/admin-dashboard/files/tests/ui/request-budget.ui.spec.ts +15 -6
  70. package/dist/templates/modules/admin-dashboard/files/tests/ui/settings-dialogs.ui.spec.ts +71 -64
  71. package/dist/templates/modules/admin-dashboard/files/tests/ui/settings.ui.spec.ts +89 -79
  72. package/dist/templates/modules/admin-dashboard/files/tests/ui/table-toolbar.ui.spec.ts +25 -0
  73. package/dist/templates/modules/admin-dashboard/files/tests/ui/two-factor.ui.spec.ts +54 -50
  74. package/dist/templates/modules/audit-log/files/apps/api/src/audit/audit-hook.ts +2 -1
  75. package/dist/templates/modules/audit-log/files/apps/api/src/audit/audit.service.spec.ts +16 -0
  76. package/dist/templates/modules/audit-log/files/apps/api/src/audit/audit.service.ts +2 -1
  77. package/dist/templates/modules/auth/files/apps/api/src/auth/auth.module.ts +4 -1
  78. package/dist/templates/modules/auth/files/apps/api/src/auth/auth.service.spec.ts +54 -6
  79. package/dist/templates/modules/auth/files/apps/api/src/auth/auth.service.ts +26 -4
  80. package/dist/templates/modules/auth/files/apps/api/src/auth/auth.ts +19 -8
  81. package/dist/templates/modules/auth/files/apps/api/src/auth/feature-gate.spec.ts +83 -0
  82. package/dist/templates/modules/auth/files/apps/api/src/auth/feature-gate.ts +51 -7
  83. package/dist/templates/modules/auth/files/apps/api/src/auth/revoke-other-sessions.spec.ts +56 -0
  84. package/dist/templates/modules/auth/files/apps/api/src/auth/revoke-other-sessions.ts +45 -0
  85. package/dist/templates/modules/rate-limit/files/apps/api/src/rate-limit/rate-limit.config.spec.ts +2 -59
  86. package/dist/templates/modules/rate-limit/files/apps/api/src/rate-limit/rate-limit.config.ts +0 -65
  87. package/dist/templates/modules/rate-limit/files/apps/api/src/rate-limit/rate-limit.identity.spec.ts +82 -21
  88. package/dist/templates/modules/rate-limit/files/apps/api/src/rate-limit/rate-limit.identity.ts +54 -15
  89. package/dist/templates/modules/rate-limit/files/apps/api/src/rate-limit/rate-limit.module.spec.ts +43 -5
  90. package/dist/templates/modules/rate-limit/files/apps/api/src/rate-limit/rate-limit.module.ts +10 -2
  91. package/dist/templates/modules/rate-limit/files/apps/api/src/rate-limit/rate-limit.routes.spec.ts +61 -3
  92. package/dist/templates/modules/rate-limit/files/apps/api/src/rate-limit/rate-limit.routes.ts +48 -15
  93. package/dist/templates/modules/rate-limit/files/tests/api/rate-limit.api.spec.ts +20 -9
  94. package/dist/templates/modules/rate-limit/module.manifest.json +6 -9
  95. package/dist/templates/todo/AGENTS.md +41 -5
  96. package/dist/templates/todo/README.md +1 -1
  97. package/package.json +2 -2
@@ -1,53 +1,57 @@
1
1
  import { expect, test } from "@playwright/test";
2
2
  import { ready } from "../helpers/hydration";
3
+ import { exclusive } from "../helpers/exclusive";
3
4
 
4
5
  // admin storageState (project default)
5
6
 
6
7
  test("settings: add and remove a social login provider", async ({ page }) => {
7
- const dialog = page.getByRole("dialog");
8
- const addBtn = dialog.getByRole("button", { name: "Add provider" });
9
- const openConfigure = async (): Promise<void> => {
10
- await page.waitForLoadState("networkidle");
11
- await page.getByRole("tab", { name: "Authentication" }).click();
12
- const socialCard = page
13
- .getByText("Social login", { exact: true })
14
- .locator('xpath=ancestor::div[@data-slot="card"]');
15
- await socialCard.getByRole("button", { name: "Configure" }).click();
16
- };
8
+ test.slow();
9
+ await exclusive("social-providers", async () => {
10
+ const dialog = page.getByRole("dialog");
11
+ const addBtn = dialog.getByRole("button", { name: "Add provider" });
12
+ const openConfigure = async (): Promise<void> => {
13
+ await page.waitForLoadState("networkidle");
14
+ await page.getByRole("tab", { name: "Authentication" }).click();
15
+ const socialCard = page
16
+ .getByText("Social login", { exact: true })
17
+ .locator('xpath=ancestor::div[@data-slot="card"]');
18
+ await socialCard.getByRole("button", { name: "Configure" }).click();
19
+ };
17
20
 
18
- await ready(page, "/admin/settings");
19
- // The auth-config catalog can be momentarily unavailable right after another
20
- // spec toggles auth config (the auth instance rebuilds). Reload until the
21
- // catalog is loaded (Add provider becomes enabled).
22
- await expect(async () => {
23
- await page.reload();
24
- await openConfigure();
25
- await expect(addBtn).toBeEnabled({ timeout: 3000 });
26
- }).toPass({ timeout: 25000 });
21
+ await ready(page, "/admin/settings");
22
+ // The auth-config catalog can be momentarily unavailable right after another
23
+ // spec toggles auth config (the auth instance rebuilds). Reload until the
24
+ // catalog is loaded (Add provider becomes enabled).
25
+ await expect(async () => {
26
+ await page.reload();
27
+ await openConfigure();
28
+ await expect(addBtn).toBeEnabled({ timeout: 3000 });
29
+ }).toPass({ timeout: 25000 });
27
30
 
28
- await addBtn.click();
29
- const provider = dialog.locator("#social-provider");
30
- await expect(provider).toBeVisible();
31
- const callback = await dialog.locator("code").textContent();
32
- const providerId = callback?.trim().split("/").pop() ?? ""; // first addable provider (not hard-coded)
33
- expect(providerId).not.toBe("");
34
- const expectedCallback = new URL(`/api/auth/callback/${providerId}`, page.url()).toString();
35
- expect(callback?.trim()).toBe(expectedCallback);
36
- try {
37
- await dialog.locator("#social-id").fill("test-client-id");
38
- await dialog.locator("#social-secret").fill("test-secret");
39
- await dialog.getByRole("button", { name: "Save", exact: true }).click();
40
- // Save returns to the list view, where the new provider row has an enable switch.
41
- await expect(dialog.getByRole("switch").first()).toBeVisible();
42
- const saved = await (await page.request.get("/api/account/auth-config")).json();
43
- expect(saved.social[providerId].redirectURI).toBe(expectedCallback);
44
- } finally {
45
- if (providerId) {
46
- await page.request
47
- .put("/api/account/auth-config", { data: { social: { [providerId]: { delete: true } } } })
48
- .catch(() => undefined);
31
+ await addBtn.click();
32
+ const provider = dialog.locator("#social-provider");
33
+ await expect(provider).toBeVisible();
34
+ const callback = await dialog.locator("code").textContent();
35
+ const providerId = callback?.trim().split("/").pop() ?? ""; // first addable provider (not hard-coded)
36
+ expect(providerId).not.toBe("");
37
+ const expectedCallback = new URL(`/api/auth/callback/${providerId}`, page.url()).toString();
38
+ expect(callback?.trim()).toBe(expectedCallback);
39
+ try {
40
+ await dialog.locator("#social-id").fill("test-client-id");
41
+ await dialog.locator("#social-secret").fill("test-secret");
42
+ await dialog.getByRole("button", { name: "Save", exact: true }).click();
43
+ // Save returns to the list view, where the new provider row has an enable switch.
44
+ await expect(dialog.getByRole("switch").first()).toBeVisible();
45
+ const saved = await (await page.request.get("/api/account/auth-config")).json();
46
+ expect(saved.social[providerId].redirectURI).toBe(expectedCallback);
47
+ } finally {
48
+ if (providerId) {
49
+ await page.request
50
+ .put("/api/account/auth-config", { data: { social: { [providerId]: { delete: true } } } })
51
+ .catch(() => undefined);
52
+ }
49
53
  }
50
- }
54
+ });
51
55
  });
52
56
 
53
57
  test("settings: open and save the SMTP dialog", async ({ page }) => {
@@ -71,31 +75,34 @@ test("settings: open and save the SMTP dialog", async ({ page }) => {
71
75
  });
72
76
 
73
77
  test("settings: configure automatic logout", async ({ page }) => {
74
- await page.request.put("/api/account/auth-config", {
75
- data: { server: { sessionIdleTimeoutMinutes: null } },
76
- });
77
- await ready(page, "/admin/settings");
78
- await page.getByRole("tab", { name: "Authentication" }).click();
78
+ test.slow();
79
+ await exclusive("session-idle-timeout", async () => {
80
+ await page.request.put("/api/account/auth-config", {
81
+ data: { server: { sessionIdleTimeoutMinutes: null } },
82
+ });
83
+ await ready(page, "/admin/settings");
84
+ await page.getByRole("tab", { name: "Authentication" }).click();
79
85
 
80
- const toggle = page.getByRole("switch", { name: "Automatic logout" });
81
- await expect(toggle).not.toBeChecked();
82
- await toggle.click();
83
- await expect(toggle).toBeChecked();
86
+ const toggle = page.getByRole("switch", { name: "Automatic logout" });
87
+ await expect(toggle).not.toBeChecked();
88
+ await toggle.click();
89
+ await expect(toggle).toBeChecked();
84
90
 
85
- const card = page
86
- .getByText("Automatic logout", { exact: true })
87
- .locator('xpath=ancestor::div[@data-slot="card"]');
88
- await card.getByRole("button", { name: "Configure" }).click();
89
- const dialog = page.getByRole("dialog");
90
- await dialog.getByLabel("Idle time (minutes)").fill("45");
91
- await dialog.getByRole("button", { name: "Save", exact: true }).click();
92
- await expect(page.getByText("45 min", { exact: true })).toBeVisible();
91
+ const card = page
92
+ .getByText("Automatic logout", { exact: true })
93
+ .locator('xpath=ancestor::div[@data-slot="card"]');
94
+ await card.getByRole("button", { name: "Configure" }).click();
95
+ const dialog = page.getByRole("dialog");
96
+ await dialog.getByLabel("Idle time (minutes)").fill("45");
97
+ await dialog.getByRole("button", { name: "Save", exact: true }).click();
98
+ await expect(page.getByText("45 min", { exact: true })).toBeVisible();
93
99
 
94
- const saved = await (await page.request.get("/api/account/auth-config")).json();
95
- expect(saved.server.sessionIdleTimeoutMinutes).toBe(45);
96
- const caps = await (await page.request.get("/api/account/capabilities")).json();
97
- expect(caps.sessionIdleTimeoutMinutes).toBe(45);
100
+ const saved = await (await page.request.get("/api/account/auth-config")).json();
101
+ expect(saved.server.sessionIdleTimeoutMinutes).toBe(45);
102
+ const caps = await (await page.request.get("/api/account/capabilities")).json();
103
+ expect(caps.sessionIdleTimeoutMinutes).toBe(45);
98
104
 
99
- await toggle.click();
100
- await expect(toggle).not.toBeChecked();
105
+ await toggle.click();
106
+ await expect(toggle).not.toBeChecked();
107
+ });
101
108
  });
@@ -1,5 +1,6 @@
1
1
  import { expect, test, type Page } from "@playwright/test";
2
2
  import { ready } from "../helpers/hydration";
3
+ import { exclusive } from "../helpers/exclusive";
3
4
 
4
5
  // admin storageState (project default)
5
6
 
@@ -30,16 +31,19 @@ test("general settings: shows the favicon uploader", async ({ page }) => {
30
31
  });
31
32
 
32
33
  test("general settings: edit the site name, save, and apply live", async ({ page }) => {
33
- await ready(page, "/admin/settings");
34
- const name = page.getByLabel("Site name");
35
- const original = await name.inputValue();
36
- await name.fill("PodoKit Test Site");
37
- await saveGeneral(page);
38
- // the browser tab title reflects the new name live (no reload)
39
- await expect(page).toHaveTitle("PodoKit Test Site");
40
- // restore so other specs start clean
41
- await name.fill(original);
42
- await saveGeneral(page);
34
+ test.slow();
35
+ await exclusive("site-general", async () => {
36
+ await ready(page, "/admin/settings");
37
+ const name = page.getByLabel("Site name");
38
+ const original = await name.inputValue();
39
+ await name.fill("PodoKit Test Site");
40
+ await saveGeneral(page);
41
+ // the browser tab title reflects the new name live (no reload)
42
+ await expect(page).toHaveTitle("PodoKit Test Site");
43
+ // restore so other specs start clean
44
+ await name.fill(original);
45
+ await saveGeneral(page);
46
+ });
43
47
  });
44
48
 
45
49
  test("settings lists the auth features under the Authentication tab", async ({ page }) => {
@@ -69,18 +73,21 @@ test("settings is reachable from the sidebar", async ({ page }) => {
69
73
  });
70
74
 
71
75
  test("admin can toggle a feature flag and it applies live @smoke", async ({ page }) => {
72
- await ready(page, "/admin/settings");
73
- await page.getByRole("tab", { name: "Authentication" }).click();
74
- const toggle = page.getByRole("switch", { name: "Magic link" });
75
- test.skip((await toggle.count()) === 0, "magic link toggle not present");
76
- // Serial workers (workers:1) make toggle-then-restore safe for other specs.
77
- await expect(toggle).toBeChecked();
78
- await toggle.click();
79
- await expect(page.getByText("Setting updated")).toBeVisible();
80
- await expect(toggle).not.toBeChecked(); // capabilities refreshed live
81
- // restore so the shared magic-link/2FA specs keep their expected state
82
- await toggle.click();
83
- await expect(toggle).toBeChecked();
76
+ test.slow();
77
+ await exclusive("magic-link", async () => {
78
+ await ready(page, "/admin/settings");
79
+ await page.getByRole("tab", { name: "Authentication" }).click();
80
+ const toggle = page.getByRole("switch", { name: "Magic link" });
81
+ test.skip((await toggle.count()) === 0, "magic link toggle not present");
82
+ // The magic-link lock keeps the API spec that toggles the same flag out.
83
+ await expect(toggle).toBeChecked();
84
+ await toggle.click();
85
+ await expect(page.getByText("Setting updated")).toBeVisible();
86
+ await expect(toggle).not.toBeChecked(); // capabilities refreshed live
87
+ // restore so the shared magic-link/2FA specs keep their expected state
88
+ await toggle.click();
89
+ await expect(toggle).toBeChecked();
90
+ });
84
91
  });
85
92
 
86
93
  test("settings: the require-two-factor toggle is available", async ({ page }) => {
@@ -95,68 +102,71 @@ test("settings: the require-two-factor toggle is available", async ({ page }) =>
95
102
  });
96
103
 
97
104
  test("inactive browser sessions are signed out automatically @smoke", async ({ browser, page: adminPage }) => {
98
- // Idle sign-out revokes the active server session. Use a dedicated login so
99
- // this test cannot invalidate the shared admin storageState used by later specs.
100
- const context = await browser.newContext({ baseURL: base });
101
- const page = await context.newPage();
102
- const email = `idle-admin-${Date.now()}@example.com`;
103
- let signOutRequests = 0;
104
- let userId = "";
105
- try {
106
- const created = await adminPage.request.post("/api/auth/admin/create-user", {
107
- headers: { origin: base },
108
- data: { email, password: "Podokit3e-Str0ng!pw", name: "Idle Admin", role: "admin" },
109
- });
110
- expect(created.ok()).toBeTruthy();
111
- userId = ((await created.json()).user?.id ?? "") as string;
112
- expect(userId).toBeTruthy();
113
-
114
- const signIn = await context.request.post("/api/auth/sign-in/email", {
115
- headers: { origin: base },
116
- data: { email, password: "Podokit3e-Str0ng!pw" },
117
- });
118
- expect(signIn.ok()).toBeTruthy();
119
-
120
- const configured = await context.request.put("/api/account/auth-config", {
121
- data: { server: { sessionIdleTimeoutMinutes: 5 } },
122
- });
123
- expect(configured.ok()).toBeTruthy();
124
- await page.route("**/api/auth/sign-out", async (route) => {
125
- signOutRequests += 1;
126
- await route.fulfill({ status: 200, contentType: "application/json", body: '{"success":true}' });
127
- });
128
- await page.clock.install();
129
-
105
+ test.slow();
106
+ await exclusive("session-idle-timeout", async () => {
107
+ // Idle sign-out revokes the active server session. Use a dedicated login so
108
+ // this test cannot invalidate the shared admin storageState used by later specs.
109
+ const context = await browser.newContext({ baseURL: base });
110
+ const page = await context.newPage();
111
+ const email = `idle-admin-${Date.now()}@example.com`;
112
+ let signOutRequests = 0;
113
+ let userId = "";
130
114
  try {
131
- await ready(page, "/admin");
132
- await expect(page.getByRole("heading", { name: "Dashboard" })).toBeVisible();
133
- } finally {
134
- // Keep the loaded page policy at five minutes while restoring the shared
135
- // DB policy before the isolated session is revoked.
136
- const restored = await context.request.put("/api/account/auth-config", {
137
- data: { server: { sessionIdleTimeoutMinutes: null } },
115
+ const created = await adminPage.request.post("/api/auth/admin/create-user", {
116
+ headers: { origin: base },
117
+ data: { email, password: "Podokit3e-Str0ng!pw", name: "Idle Admin", role: "admin" },
138
118
  });
139
- expect(restored.ok()).toBeTruthy();
140
- }
119
+ expect(created.ok()).toBeTruthy();
120
+ userId = ((await created.json()).user?.id ?? "") as string;
121
+ expect(userId).toBeTruthy();
141
122
 
142
- const removed = await adminPage.request.post("/api/auth/admin/remove-user", {
143
- headers: { origin: base },
144
- data: { userId },
145
- });
146
- expect(removed.ok()).toBeTruthy();
147
- userId = "";
148
-
149
- await page.clock.fastForward(5 * 60_000 + 1_000);
150
- await expect.poll(() => signOutRequests).toBe(1);
151
- await expect(page).toHaveURL(/\/login\?reason=idle$/);
152
- await expect(page.getByTestId("session-timeout-message")).toBeVisible();
153
- } finally {
154
- if (userId) {
155
- await adminPage.request.post("/api/auth/admin/remove-user", {
123
+ const signIn = await context.request.post("/api/auth/sign-in/email", {
124
+ headers: { origin: base },
125
+ data: { email, password: "Podokit3e-Str0ng!pw" },
126
+ });
127
+ expect(signIn.ok()).toBeTruthy();
128
+
129
+ const configured = await context.request.put("/api/account/auth-config", {
130
+ data: { server: { sessionIdleTimeoutMinutes: 5 } },
131
+ });
132
+ expect(configured.ok()).toBeTruthy();
133
+ await page.route("**/api/auth/sign-out", async (route) => {
134
+ signOutRequests += 1;
135
+ await route.fulfill({ status: 200, contentType: "application/json", body: '{"success":true}' });
136
+ });
137
+ await page.clock.install();
138
+
139
+ try {
140
+ await ready(page, "/admin");
141
+ await expect(page.getByRole("heading", { name: "Dashboard" })).toBeVisible();
142
+ } finally {
143
+ // Keep the loaded page policy at five minutes while restoring the shared
144
+ // DB policy before the isolated session is revoked.
145
+ const restored = await context.request.put("/api/account/auth-config", {
146
+ data: { server: { sessionIdleTimeoutMinutes: null } },
147
+ });
148
+ expect(restored.ok()).toBeTruthy();
149
+ }
150
+
151
+ const removed = await adminPage.request.post("/api/auth/admin/remove-user", {
156
152
  headers: { origin: base },
157
153
  data: { userId },
158
154
  });
155
+ expect(removed.ok()).toBeTruthy();
156
+ userId = "";
157
+
158
+ await page.clock.fastForward(5 * 60_000 + 1_000);
159
+ await expect.poll(() => signOutRequests).toBe(1);
160
+ await expect(page).toHaveURL(/\/login\?reason=idle$/);
161
+ await expect(page.getByTestId("session-timeout-message")).toBeVisible();
162
+ } finally {
163
+ if (userId) {
164
+ await adminPage.request.post("/api/auth/admin/remove-user", {
165
+ headers: { origin: base },
166
+ data: { userId },
167
+ });
168
+ }
169
+ await context.close();
159
170
  }
160
- await context.close();
161
- }
171
+ });
162
172
  });
@@ -59,3 +59,28 @@ test("users toolbar can pick the search field", async ({ page }) => {
59
59
  await page.getByRole("option", { name: "Name", exact: true }).click();
60
60
  await expect(fieldSelect).toContainText("Name");
61
61
  });
62
+
63
+ test("users toolbar keeps the search box usable at phone width", async ({ page }) => {
64
+ await page.setViewportSize({ width: 390, height: 844 });
65
+ await ready(page, "/admin/users");
66
+ const input = await page.locator("#toolbar-search").boundingBox();
67
+ const field = await page.locator('button[data-slot="select-trigger"]').last().boundingBox();
68
+ const button = await page.getByRole("button", { name: "Search", exact: true }).boundingBox();
69
+ if (!input || !field || !button) throw new Error("expected the toolbar to render");
70
+ // The input wraps below the field select instead of shrinking beside it.
71
+ expect(input.width).toBeGreaterThanOrEqual(192);
72
+ expect(input.y).toBeGreaterThan(field.y + field.height);
73
+ expect(Math.abs(input.y + input.height / 2 - (button.y + button.height / 2))).toBeLessThan(1);
74
+ expect(await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth))
75
+ .toBe(0);
76
+ });
77
+
78
+ test("users toolbar keeps the desktop search box on one row", async ({ page }) => {
79
+ await page.setViewportSize({ width: 1280, height: 800 });
80
+ await ready(page, "/admin/users");
81
+ const input = await page.locator("#toolbar-search").boundingBox();
82
+ const field = await page.locator('button[data-slot="select-trigger"]').last().boundingBox();
83
+ if (!input || !field) throw new Error("expected the toolbar to render");
84
+ expect(input.width).toBe(320);
85
+ expect(Math.abs(input.y + input.height / 2 - (field.y + field.height / 2))).toBeLessThan(1);
86
+ });
@@ -1,6 +1,7 @@
1
1
  import { expect, test, type Page } from "@playwright/test";
2
2
  import { ADMIN, USER, anonState } from "../helpers/accounts";
3
3
  import { totpCode } from "../helpers/totp";
4
+ import { exclusive } from "../helpers/exclusive";
4
5
 
5
6
  test.use({ storageState: anonState });
6
7
 
@@ -85,58 +86,61 @@ test("two-factor: sign in with an authenticator code from the login page", async
85
86
  });
86
87
 
87
88
  test("require-2fa: a new sign-up is forced through the enrolment page", async ({ page, playwright }) => {
88
- const admin = await playwright.request.newContext({ baseURL: base, extraHTTPHeaders: origin });
89
- const caps = await (await admin.get("/api/account/capabilities")).json();
90
- test.skip(!caps?.twoFactor, "two-factor not enabled");
91
- await admin.post("/api/auth/sign-in/email", { data: { email: ADMIN.email, password: ADMIN.password } });
92
-
93
- const email = `rq-ui-${Date.now()}@example.com`;
94
- const pw = "Podokit3e-Str0ng!pw";
95
- try {
96
- await admin.put("/api/account/settings", { data: { require2fa: true } });
97
- // A fresh un-enrolled user; poll (via API) until the guard cache picks up the policy.
98
- const probe = await playwright.request.newContext({ baseURL: base, extraHTTPHeaders: origin });
99
- await probe.post("/api/auth/sign-up/email", { data: { email, password: pw, name: "RQUI" } });
100
- await expect(async () => {
101
- expect((await probe.get("/api/account/me")).status()).toBe(403);
102
- }).toPass({ timeout: 8000 });
103
- await probe.dispose();
104
-
105
- // Signing in toward a protected route lands on the mandatory enrolment page.
106
- await openHydratedLogin(page, "/account");
107
- await page.getByLabel("Email").fill(email);
108
- await page.getByLabel("Password").fill(pw);
109
- await page.getByRole("button", { name: "Sign in", exact: true }).click();
110
- await expect(page).toHaveURL(/\/setup-2fa/);
111
-
112
- // Complete enrolment entirely through the UI: password → QR + backup codes →
113
- // authenticator code → activate. The code is computed from the on-page URI.
114
- await page.getByLabel("Confirm your password").fill(pw);
115
- await page.getByRole("button", { name: "Continue" }).click();
116
- await expect(page.getByTestId("backup-codes")).toBeVisible();
117
- await expect(page.getByRole("button", { name: "Download" })).toBeVisible();
118
- const uri = (await page.locator("code").first().innerText()).trim();
119
- await page.getByRole("checkbox").click();
120
- await page.getByLabel("3. Enter the 6-digit code").fill(totpCode(uri));
121
- await page.getByRole("button", { name: "Activate and continue" }).click();
122
-
123
- // Enrolled → the gate lets the regular user into their account page.
124
- await expectAccountPage(page);
125
-
126
- // An enrolled user who revisits setup is returned to the same non-admin page.
127
- await page.goto("/setup-2fa");
128
- await expectAccountPage(page);
129
- } finally {
130
- await admin.put("/api/account/settings", { data: { require2fa: false } });
131
- await expect(async () => {
89
+ test.slow();
90
+ await exclusive("require2fa", async () => {
91
+ const admin = await playwright.request.newContext({ baseURL: base, extraHTTPHeaders: origin });
92
+ const caps = await (await admin.get("/api/account/capabilities")).json();
93
+ test.skip(!caps?.twoFactor, "two-factor not enabled");
94
+ await admin.post("/api/auth/sign-in/email", { data: { email: ADMIN.email, password: ADMIN.password } });
95
+
96
+ const email = `rq-ui-${Date.now()}@example.com`;
97
+ const pw = "Podokit3e-Str0ng!pw";
98
+ try {
99
+ await admin.put("/api/account/settings", { data: { require2fa: true } });
100
+ // A fresh un-enrolled user; poll (via API) until the guard cache picks up the policy.
132
101
  const probe = await playwright.request.newContext({ baseURL: base, extraHTTPHeaders: origin });
133
- await probe.post("/api/auth/sign-in/email", { data: { email: USER.email, password: USER.password } });
134
- const status = (await probe.get("/api/account/me")).status();
102
+ await probe.post("/api/auth/sign-up/email", { data: { email, password: pw, name: "RQUI" } });
103
+ await expect(async () => {
104
+ expect((await probe.get("/api/account/me")).status()).toBe(403);
105
+ }).toPass({ timeout: 8000 });
135
106
  await probe.dispose();
136
- expect(status).toBe(200);
137
- }).toPass({ timeout: 8000 });
138
- await admin.dispose();
139
- }
107
+
108
+ // Signing in toward a protected route lands on the mandatory enrolment page.
109
+ await openHydratedLogin(page, "/account");
110
+ await page.getByLabel("Email").fill(email);
111
+ await page.getByLabel("Password").fill(pw);
112
+ await page.getByRole("button", { name: "Sign in", exact: true }).click();
113
+ await expect(page).toHaveURL(/\/setup-2fa/);
114
+
115
+ // Complete enrolment entirely through the UI: password → QR + backup codes →
116
+ // authenticator code → activate. The code is computed from the on-page URI.
117
+ await page.getByLabel("Confirm your password").fill(pw);
118
+ await page.getByRole("button", { name: "Continue" }).click();
119
+ await expect(page.getByTestId("backup-codes")).toBeVisible();
120
+ await expect(page.getByRole("button", { name: "Download" })).toBeVisible();
121
+ const uri = (await page.locator("code").first().innerText()).trim();
122
+ await page.getByRole("checkbox").click();
123
+ await page.getByLabel("3. Enter the 6-digit code").fill(totpCode(uri));
124
+ await page.getByRole("button", { name: "Activate and continue" }).click();
125
+
126
+ // Enrolled → the gate lets the regular user into their account page.
127
+ await expectAccountPage(page);
128
+
129
+ // An enrolled user who revisits setup is returned to the same non-admin page.
130
+ await page.goto("/setup-2fa");
131
+ await expectAccountPage(page);
132
+ } finally {
133
+ await admin.put("/api/account/settings", { data: { require2fa: false } });
134
+ await expect(async () => {
135
+ const probe = await playwright.request.newContext({ baseURL: base, extraHTTPHeaders: origin });
136
+ await probe.post("/api/auth/sign-in/email", { data: { email: USER.email, password: USER.password } });
137
+ const status = (await probe.get("/api/account/me")).status();
138
+ await probe.dispose();
139
+ expect(status).toBe(200);
140
+ }).toPass({ timeout: 8000 });
141
+ await admin.dispose();
142
+ }
143
+ });
140
144
  });
141
145
 
142
146
  test("account: regenerate backup codes shows a fresh set", async ({ page, playwright }) => {
@@ -1,4 +1,5 @@
1
1
  import { createAuthMiddleware } from "better-auth/api";
2
+ import { clientAddressOf } from "../core/client-address";
2
3
  import { recordAudit } from "./audit-events";
3
4
  import { auditEnabled } from "./audit-enabled";
4
5
 
@@ -71,6 +72,6 @@ export const auditAfterHook = createAuthMiddleware(async (ctx) => {
71
72
  actorEmail: actor?.email ?? null,
72
73
  targetId,
73
74
  targetLabel,
74
- ip: ctx.headers?.get("x-forwarded-for") ?? null,
75
+ ip: clientAddressOf(ctx.headers) ?? null,
75
76
  });
76
77
  });
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, mock, test } from "bun:test";
2
2
  import { SQL } from "bun";
3
3
  import type { QueryRunner } from "typeorm";
4
4
  import type { AuthSession } from "../auth/auth.service";
5
+ import { CLIENT_ADDRESS_HEADER } from "../core/client-address";
5
6
  import { InitAuditLogs1720300000000 } from "../migrations/1720300000000-InitAuditLogs";
6
7
  import { recordAudit, recordAuditLater } from "./audit-events";
7
8
  import { AppException } from "@podosoft/podokit-contracts";
@@ -176,6 +177,21 @@ describe("AuditService", () => {
176
177
  }
177
178
  });
178
179
 
180
+ test("records the address the API resolved, not the caller's forwarded header", async () => {
181
+ const capture = sqlCapture();
182
+ const service = new AuditService(capture.sql, { dialect: "postgres", enabled: on });
183
+ const session: AuthSession = { user: { id: "user-1" }, session: {} };
184
+ const headers = {
185
+ "x-forwarded-for": "198.51.100.66, 198.51.100.67",
186
+ [CLIENT_ADDRESS_HEADER]: "203.0.113.7",
187
+ };
188
+ await service.recordRequest("todo.create", new Request("http://localhost/todos", { headers }), session);
189
+ await service.recordRequest("todo.delete", new Request("http://localhost/todos", {
190
+ headers: { "x-forwarded-for": "198.51.100.66" },
191
+ }), session);
192
+ expect(capture.batches.map((batch) => batch[0]?.ip)).toEqual(["203.0.113.7", null]);
193
+ });
194
+
179
195
  test("a failing toggle read never breaks the caller", async () => {
180
196
  const sql = await sqliteDatabase();
181
197
  const service = new AuditService(sql, {
@@ -2,6 +2,7 @@ import type { SQL } from "bun";
2
2
  import { AppException } from "@podosoft/podokit-contracts";
3
3
  import type { DatabaseProviderName } from "@podosoft/podokit-runtime";
4
4
  import type { AuthSession } from "../auth/auth.service";
5
+ import { clientAddressOf } from "../core/client-address";
5
6
  import { setAuditRecorder, type AuditEntry } from "./audit-events";
6
7
 
7
8
  export interface AuditLogView extends AuditEntry {
@@ -412,7 +413,7 @@ export class AuditService {
412
413
  targetId: target.id ?? null,
413
414
  targetLabel: target.label ?? null,
414
415
  metadata: target.metadata ?? null,
415
- ip: request.headers.get("x-forwarded-for") ?? null,
416
+ ip: clientAddressOf(request.headers) ?? null,
416
417
  };
417
418
  if (options.defer) this.recordLater(entry);
418
419
  else await this.record(entry);
@@ -8,6 +8,7 @@ import {
8
8
  OPENAPI,
9
9
  REQUEST_GUARDS,
10
10
  REQUEST_IDENTITY,
11
+ RESOLVED_SESSIONS,
11
12
  type AppPlugin,
12
13
  type PodokitModule,
13
14
  type ServiceKey,
@@ -158,7 +159,9 @@ export const authModule: PodokitModule = {
158
159
  setMailConfigStore(authConfigStore);
159
160
  const accessPolicy = services.resolve(ACCESS_POLICY);
160
161
  const settings = new SettingsService(database.sql, authConfigStore, publishConfigChanged);
161
- const authService = new AuthService(settings, accessPolicy);
162
+ const authService = new AuthService(settings, accessPolicy, {
163
+ resolvedSessions: services.resolve(RESOLVED_SESSIONS),
164
+ });
162
165
  services.register(SETTINGS, settings);
163
166
  services.register(AUTH_CONFIG, new AuthConfigService(database.sql, database.provider));
164
167
  services.register(AUTH, authService, () => authService.close());