⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
feat(admin): audit test emails
Tinbaee8c71edec
diff --git a/apps/api/src/admin/controllers/send-test-email.ts b/apps/api/src/admin/controllers/send-test-email.tsindex 0d47244a6..54409150a 100644--- a/apps/api/src/admin/controllers/send-test-email.ts+++ b/apps/api/src/admin/controllers/send-test-email.ts@@ -5,6 +5,8 @@ import {} from "@kaneo/email";import { HTTPException } from "hono/http-exception";import { ApiError } from "../../errors/api-error";+import type { AdminAuditRequest } from "../audit/admin-audit-request";+import { recordAdminAction } from "../audit/record-admin-action";import { createAttemptLimiter } from "../system/attempt-limiter";const testEmailLimiter = createAttemptLimiter({@@ -29,7 +31,10 @@ type SendTestEmailInput = {* Send an SMTP test to the calling administrator's own address. There is no* recipient parameter, so this can't be used to relay mail to anyone else.*/-async function sendAdminTestEmail({ userId, email }: SendTestEmailInput) {+async function sendAdminTestEmail(+ { userId, email }: SendTestEmailInput,+ audit: AdminAuditRequest,+) {if (!isSmtpConfigured()) throw notConfigured();const decision = testEmailLimiter.take(userId);@@ -68,6 +73,14 @@ async function sendAdminTestEmail({ userId, email }: SendTestEmailInput) {if (!result.success) throw notConfigured();+ await recordAdminAction({+ ...audit,+ action: "email.test_sent",+ targetType: "user",+ targetId: userId,+ targetLabel: email,+ });+return { sent: true as const, to: email };}diff --git a/apps/api/src/admin/index.ts b/apps/api/src/admin/index.tsindex 1856a92e5..9143cf3c3 100644--- a/apps/api/src/admin/index.ts+++ b/apps/api/src/admin/index.ts@@ -323,10 +323,10 @@ const admin = apiRouter()).openapi(sendTestEmailRoute, async (c) =>c.json(- await sendAdminTestEmail({- userId: c.get("userId"),- email: c.get("userEmail"),- }),+ await sendAdminTestEmail(+ { userId: c.get("userId"), email: c.get("userEmail") },+ adminAuditRequest(c),+ ),200,),)diff --git a/apps/docs/core/operations/administration.mdx b/apps/docs/core/operations/administration.mdxindex 638e20988..8eefd85d7 100644--- a/apps/docs/core/operations/administration.mdx+++ b/apps/docs/core/operations/administration.mdx@@ -61,11 +61,12 @@ The only owner can't be removed or given another role. Transfer ownership to som## Review the audit log-Open **Settings → Administration → Audit log** to see what administrators changed, newest first. Each entry shows the action, the administrator who did it, the affected user or workspace, the time, and the IP address the request came from. Filter by users, sessions, API keys, or workspaces to narrow the list.+Open **Settings → Administration → Audit log** to see what administrators changed, newest first. Each entry shows the action, the administrator who did it, the affected user or workspace, the time, and the IP address the request came from. Filter by users, sessions, API keys, workspaces, or email to narrow the list.Kaneo records these actions when they succeed. Rejected or failed attempts aren't recorded.- **Users:** created, details updated (which fields changed), instance role changed, deactivated, reactivated, deleted, password set by an administrator, password reset link sent, verification email sent, email marked verified, profile picture changed or removed, and signed in as the user (impersonation).+- **Email:** test email sent to the calling administrator.- **Sessions:** one session or all of a user's sessions revoked.- **API keys:** a user's API key revoked (its name, never its value).- **Workspaces:** member added, member removed, member role changed, and ownership transferred.diff --git a/apps/web/src/components/admin/audit-log/audit-log-categories.ts b/apps/web/src/components/admin/audit-log/audit-log-categories.tsindex 5138412bd..f52db7d3f 100644--- a/apps/web/src/components/admin/audit-log/audit-log-categories.ts+++ b/apps/web/src/components/admin/audit-log/audit-log-categories.ts@@ -2,6 +2,7 @@export const AUDIT_LOG_CATEGORIES = [{ value: "", labelKey: "settings:adminAuditLog.categories.all" },{ value: "user", labelKey: "settings:adminAuditLog.categories.user" },+ { value: "email", labelKey: "settings:adminAuditLog.categories.email" },{ value: "session", labelKey: "settings:adminAuditLog.categories.session" },{ value: "api_key", labelKey: "settings:adminAuditLog.categories.apiKey" },{diff --git a/apps/web/src/components/admin/audit-log/get-audit-action-label.ts b/apps/web/src/components/admin/audit-log/get-audit-action-label.tsindex c3ebbf9cb..70eeb8545 100644--- a/apps/web/src/components/admin/audit-log/get-audit-action-label.ts+++ b/apps/web/src/components/admin/audit-log/get-audit-action-label.ts@@ -1,4 +1,5 @@const ACTION_LABEL_KEYS = new Map([+ ["email.test_sent", "settings:adminAuditLog.actions.emailTestSent"],["user.created", "settings:adminAuditLog.actions.userCreated"],["user.updated", "settings:adminAuditLog.actions.userUpdated"],["user.role_changed", "settings:adminAuditLog.actions.userRoleChanged"],diff --git a/apps/web/src/hooks/mutations/admin/use-send-admin-test-email.test.tsx b/apps/web/src/hooks/mutations/admin/use-send-admin-test-email.test.tsxnew file mode 100644index 000000000..b3cdf416e--- /dev/null+++ b/apps/web/src/hooks/mutations/admin/use-send-admin-test-email.test.tsx@@ -0,0 +1,76 @@+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { act, cleanup, renderHook, waitFor } from "@testing-library/react";+import type { ReactNode } from "react";+import { afterEach, describe, expect, it, vi } from "vite-plus/test";+import { sendAdminTestEmail } from "@/fetchers/admin/send-admin-test-email";+import useSendAdminTestEmail from "./use-send-admin-test-email";++vi.mock("@/components/providers/auth-provider/hooks/use-auth", () => ({+ default: () => ({ user: null }),+}));+vi.mock("@/fetchers/admin/send-admin-test-email", () => ({+ sendAdminTestEmail: vi.fn(),+}));+vi.mock("react-i18next", () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));+vi.mock("@/lib/toast", () => ({+ toast: { success: vi.fn(), error: vi.fn() },+}));++afterEach(cleanup);++const auditKey = ["admin", "audit-log", "admin-id", "email", 0];++function renderSend() {+ const client = new QueryClient({+ defaultOptions: { queries: { refetchOnMount: false } },+ });+ const reloadAudit = vi.fn().mockResolvedValue({+ entries: [{ id: "sent" }],+ total: 1,+ });+ client.setQueryDefaults(auditKey, { queryFn: reloadAudit });+ client.setQueryData(auditKey, { entries: [], total: 0 });+ const hook = renderHook(useSendAdminTestEmail, {+ wrapper: ({ children }: { children: ReactNode }) => (+ <QueryClientProvider client={client}>{children}</QueryClientProvider>+ ),+ });+ return { client, reloadAudit, ...hook };+}++describe("useSendAdminTestEmail", () => {+ it("refreshes previously visited audit pages after a successful send", async () => {+ vi.mocked(sendAdminTestEmail).mockResolvedValue({+ sent: true,+ to: "[email protected]",+ });+ const { client, result } = renderSend();++ await act(async () => {+ await result.current.mutateAsync();+ });++ await waitFor(() => {+ expect(client.getQueryData(auditKey)).toEqual({+ entries: [{ id: "sent" }],+ total: 1,+ });+ });+ client.clear();+ });++ it("leaves audit entries current when the send fails", async () => {+ vi.mocked(sendAdminTestEmail).mockRejectedValue(new Error("Send failed"));+ const { client, reloadAudit, result } = renderSend();++ await act(async () => {+ await expect(result.current.mutateAsync()).rejects.toThrow("Send failed");+ });++ expect(client.getQueryState(auditKey)?.isInvalidated).toBe(false);+ expect(reloadAudit).not.toHaveBeenCalled();+ client.clear();+ });+});diff --git a/apps/web/src/hooks/mutations/admin/use-send-admin-test-email.ts b/apps/web/src/hooks/mutations/admin/use-send-admin-test-email.tsindex 144427bcd..638455b4d 100644--- a/apps/web/src/hooks/mutations/admin/use-send-admin-test-email.ts+++ b/apps/web/src/hooks/mutations/admin/use-send-admin-test-email.ts@@ -1,15 +1,21 @@-import { useMutation } from "@tanstack/react-query";+import { useMutation, useQueryClient } from "@tanstack/react-query";import { MailCheckIcon } from "lucide-react";import { useTranslation } from "react-i18next";import { sendAdminTestEmail } from "@/fetchers/admin/send-admin-test-email";+import { ADMIN_AUDIT_LOG_QUERY_KEY } from "@/hooks/queries/admin/use-admin-audit-log";import { toast } from "@/lib/toast";function useSendAdminTestEmail() {const { t } = useTranslation();+ const queryClient = useQueryClient();return useMutation({mutationFn: sendAdminTestEmail,onSuccess: ({ to }) => {+ void queryClient.invalidateQueries({+ queryKey: ADMIN_AUDIT_LOG_QUERY_KEY,+ refetchType: "all",+ });toast.success(t("settings:adminSystem.toast.testEmailSent", { to }), {icon: MailCheckIcon,});diff --git a/i18n/az-AZ.json b/i18n/az-AZ.jsonindex 3c461294b..49610adec 100644--- a/i18n/az-AZ.json+++ b/i18n/az-AZ.json@@ -2485,14 +2485,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/de-DE.json b/i18n/de-DE.jsonindex e4930cd56..ad3a5d427 100644--- a/i18n/de-DE.json+++ b/i18n/de-DE.json@@ -2485,14 +2485,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/el-GR.json b/i18n/el-GR.jsonindex ff60bc60f..5f01a86ba 100644--- a/i18n/el-GR.json+++ b/i18n/el-GR.json@@ -2485,14 +2485,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/en-US.json b/i18n/en-US.jsonindex 5d097987a..7da097223 100644--- a/i18n/en-US.json+++ b/i18n/en-US.json@@ -888,6 +888,7 @@"categoryLabel": "Filter by category","categories": {"all": "All actions",+ "email": "Email","user": "Users","session": "Sessions","workspace": "Workspaces",@@ -914,6 +915,7 @@"workspace": "Workspace"},"actions": {+ "emailTestSent": "Sent test email","userCreated": "Created user","userUpdated": "Updated user details","userRoleChanged": "Changed instance role",diff --git a/i18n/es-ES.json b/i18n/es-ES.jsonindex 4e206c4ca..f6260b4a4 100644--- a/i18n/es-ES.json+++ b/i18n/es-ES.json@@ -2527,14 +2527,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/fr-FR.json b/i18n/fr-FR.jsonindex 186d5e29f..e846f6b54 100644--- a/i18n/fr-FR.json+++ b/i18n/fr-FR.json@@ -2527,14 +2527,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/hi-IN.json b/i18n/hi-IN.jsonindex c8c7b3e26..c9ef050c0 100644--- a/i18n/hi-IN.json+++ b/i18n/hi-IN.json@@ -2485,14 +2485,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/id-ID.json b/i18n/id-ID.jsonindex 5d7cc0060..cd5b41a2d 100644--- a/i18n/id-ID.json+++ b/i18n/id-ID.json@@ -2443,14 +2443,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/it-IT.json b/i18n/it-IT.jsonindex 53ebe0d44..32e878b9f 100644--- a/i18n/it-IT.json+++ b/i18n/it-IT.json@@ -2527,14 +2527,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/ja-JP.json b/i18n/ja-JP.jsonindex 35cbf68d2..b565141e6 100644--- a/i18n/ja-JP.json+++ b/i18n/ja-JP.json@@ -2443,14 +2443,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/ko-KR.json b/i18n/ko-KR.jsonindex 6c3edd9ea..503d5846b 100644--- a/i18n/ko-KR.json+++ b/i18n/ko-KR.json@@ -2443,14 +2443,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/mk-MK.json b/i18n/mk-MK.jsonindex c8321226a..341d86100 100644--- a/i18n/mk-MK.json+++ b/i18n/mk-MK.json@@ -2485,14 +2485,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/nl-NL.json b/i18n/nl-NL.jsonindex ce38a13f1..b3b82a76d 100644--- a/i18n/nl-NL.json+++ b/i18n/nl-NL.json@@ -2485,14 +2485,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/pl-PL.json b/i18n/pl-PL.jsonindex d5d45dc5e..dcd3c1a95 100644--- a/i18n/pl-PL.json+++ b/i18n/pl-PL.json@@ -3254,14 +3254,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/pt-BR.json b/i18n/pt-BR.jsonindex 6ba734968..4a9018610 100644--- a/i18n/pt-BR.json+++ b/i18n/pt-BR.json@@ -2527,14 +2527,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/ru-RU.json b/i18n/ru-RU.jsonindex e2a1b71c2..b59ec1e94 100644--- a/i18n/ru-RU.json+++ b/i18n/ru-RU.json@@ -2577,14 +2577,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/tr-TR.json b/i18n/tr-TR.jsonindex a44903554..ff598e189 100644--- a/i18n/tr-TR.json+++ b/i18n/tr-TR.json@@ -2485,14 +2485,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/uk-UA.json b/i18n/uk-UA.jsonindex a6cb0600b..5921b8ac4 100644--- a/i18n/uk-UA.json+++ b/i18n/uk-UA.json@@ -2569,14 +2569,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/vi-VN.json b/i18n/vi-VN.jsonindex 4d80190f6..9173b35d6 100644--- a/i18n/vi-VN.json+++ b/i18n/vi-VN.json@@ -2443,14 +2443,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/zh-CN.json b/i18n/zh-CN.jsonindex dce07f39d..b85b41ab9 100644--- a/i18n/zh-CN.json+++ b/i18n/zh-CN.json@@ -2443,14 +2443,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/i18n/zh-TW.json b/i18n/zh-TW.jsonindex 2a2088144..745ae26f4 100644--- a/i18n/zh-TW.json+++ b/i18n/zh-TW.json@@ -2443,14 +2443,16 @@"userEmailVerified": "Marked email as verified","userPasswordResetSent": "Sent password reset link","userVerificationSent": "Sent verification email",- "apiKeyRevoked": "Revoked an API key"+ "apiKeyRevoked": "Revoked an API key",+ "emailTestSent": "Sent test email"},"categories": {"all": "All actions","session": "Sessions","user": "Users","workspace": "Workspaces",- "apiKey": "API keys"+ "apiKey": "API keys",+ "email": "Email"},"categoryLabel": "Filter by category","clearFilter": "Show all actions",diff --git a/tests/api-integration/admin-system-status.test.ts b/tests/api-integration/admin-system-status.test.tsindex eb87f5d7c..2adc27fdf 100644--- a/tests/api-integration/admin-system-status.test.ts+++ b/tests/api-integration/admin-system-status.test.ts@@ -4,6 +4,7 @@ import { beforeEach, describe, expect, it, vi } from "vite-plus/test";import db, { schema } from "../../apps/api/src/database";import { mockAnonymousSession, mockAuthenticatedSession } from "./helpers/auth";import { createInstanceAdmin } from "./helpers/admin/create-instance-admin";+import { readAuditLog } from "./helpers/admin/read-audit-log";import { resetTestDatabase } from "./helpers/database";import { createRestrictedWorkspace } from "./helpers/project-access/create-restricted-workspace";import { projectAccessApi } from "./helpers/project-access/project-access-api";@@ -114,6 +115,7 @@ describe("admin system status", () => {.status,).toBe(403);expect(smtp.send).not.toHaveBeenCalled();+ expect(await readAuditLog()).toEqual([]);});it("rejects API keys even when they belong to an administrator", async () => {@@ -128,6 +130,7 @@ describe("admin system status", () => {(await request("/admin/system/test-email", { method: "POST" })).status,).toBe(403);expect(smtp.send).not.toHaveBeenCalled();+ expect(await readAuditLog()).toEqual([]);});it("reports each service, treating optional ones as not configured", async () => {@@ -318,14 +321,17 @@ describe("admin test email", () => {code: "SMTP_NOT_CONFIGURED",});expect(smtp.send).not.toHaveBeenCalled();+ expect(await readAuditLog()).toEqual([]);});- it("only ever sends to the calling administrator", async () => {+ it("only sends to the calling administrator and records exactly one audit entry", async () => {smtp.configured.mockReturnValue(true);const admin = await createInstanceAdmin();mockAuthenticatedSession(admin);- const response = await projectAccessApi()("/admin/system/test-email", {+ const response = await projectAccessApi({+ "user-agent": "email-audit-agent",+ })("/admin/system/test-email", {method: "POST",body: { to: "[email protected]", email: "[email protected]" },});@@ -337,6 +343,22 @@ describe("admin test email", () => {const calls = JSON.stringify(smtp.send.mock.calls);expect(calls).not.toContain("someone-else@");expect(calls).not.toContain("victim@");++ const rows = await readAuditLog();+ expect(rows).toHaveLength(1);+ expect(rows[0]).toMatchObject({+ action: "email.test_sent",+ actorUserId: admin.id,+ actorName: admin.name,+ actorEmail: admin.email,+ targetType: "user",+ targetId: admin.id,+ targetLabel: admin.email,+ metadata: null,+ userAgent: "email-audit-agent",+ });+ expect(JSON.stringify(rows)).not.toContain("someone-else@");+ expect(JSON.stringify(rows)).not.toContain("victim@");});it("returns a safe error when the mail server rejects the message", async () => {@@ -364,6 +386,22 @@ describe("admin test email", () => {expect(JSON.stringify(vi.mocked(console.error).mock.calls)).not.toContain("smtp-password-value",);+ expect(await readAuditLog()).toEqual([]);+ });++ it("does not record an audit entry when delivery reports no success", async () => {+ smtp.configured.mockReturnValue(true);+ smtp.send.mockResolvedValue({ success: false });+ const admin = await createInstanceAdmin();+ mockAuthenticatedSession(admin);++ const response = await projectAccessApi()("/admin/system/test-email", {+ method: "POST",+ });++ expect(response.status).toBe(409);+ expect(smtp.send).toHaveBeenCalledTimes(1);+ expect(await readAuditLog()).toEqual([]);});it("limits how often one administrator can send", async () => {@@ -377,6 +415,11 @@ describe("admin test email", () => {(await request("/admin/system/test-email", { method: "POST" })).status,).toBe(200);}+ const rowsBeforeLimit = await readAuditLog();+ expect(rowsBeforeLimit).toHaveLength(5);+ expect(+ rowsBeforeLimit.every((row) => row.action === "email.test_sent"),+ ).toBe(true);const limited = await request("/admin/system/test-email", {method: "POST",});@@ -385,5 +428,6 @@ describe("admin test email", () => {expect(Number(limited.headers.get("retry-after"))).toBeGreaterThan(0);expect(await limited.json()).toMatchObject({ code: "RATE_LIMITED" });expect(smtp.send).toHaveBeenCalledTimes(5);+ expect(await readAuditLog()).toEqual(rowsBeforeLimit);});});