Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Harden diagnostics onboarding export proof

rcourtman0f767b643972
diff --git a/frontend-modern/src/components/Settings/__tests__/diagnosticsModel.test.ts b/frontend-modern/src/components/Settings/__tests__/diagnosticsModel.test.ts
new file mode 100644
index 0000000000..3a101fbc9c
--- /dev/null
+++ b/frontend-modern/src/components/Settings/__tests__/diagnosticsModel.test.ts
@@ -0,0 +1,148 @@
+import { describe, expect, it } from 'vitest';
+import {
+ buildDiagnosticsExportFilename,
+ sanitizeDiagnosticsData,
+ type DiagnosticsData,
+} from '@/components/Settings/diagnosticsModel';
+
+const createDiagnosticsData = (): DiagnosticsData => ({
+ version: '6.0.0',
+ runtime: 'go',
+ uptime: 3600,
+ nodes: [
+ {
+ id: 'node-raw-id',
+ name: 'pve-01',
+ host: '10.0.0.5',
+ type: 'pve',
+ authMethod: 'token',
+ connected: false,
+ error: 'dial tcp 10.0.0.5:8006: connect: connection refused',
+ },
+ ],
+ pbs: [
+ {
+ id: 'pbs-raw-id',
+ name: 'pbs-01',
+ host: '10.0.0.15',
+ connected: false,
+ error: 'Get https://10.0.0.15:8007: EOF',
+ },
+ ],
+ system: {
+ os: 'linux',
+ arch: 'amd64',
+ goVersion: 'go1.25',
+ numCPU: 8,
+ numGoroutine: 32,
+ memoryMB: 128,
+ },
+ discovery: {
+ enabled: true,
+ configuredSubnet: '10.0.0.0/24',
+ activeSubnet: '10.0.1.0/24',
+ environmentOverride: 'PULSE_DISCOVERY_SUBNET=10.0.2.0/24',
+ subnetAllowlist: ['10.0.0.0/24'],
+ subnetBlocklist: ['10.0.3.0/24'],
+ history: [
+ {
+ startedAt: '2026-04-20T10:00:00Z',
+ completedAt: '2026-04-20T10:00:10Z',
+ duration: '10s',
+ durationMs: 10000,
+ subnet: '10.0.0.0/24',
+ serverCount: 4,
+ errorCount: 1,
+ blocklistLength: 1,
+ status: 'completed',
+ },
+ ],
+ },
+ infrastructureOnboarding: {
+ enabled: true,
+ status: 'warning',
+ windowDays: 30,
+ summary: {
+ opened: 4,
+ api_path_selected: 2,
+ agent_path_selected: 1,
+ probe_detected: 1,
+ probe_no_match: 2,
+ probe_error: 0,
+ catalog_selected: 2,
+ credentials_opened: 1,
+ period: {
+ from: '2026-03-19T00:00:00Z',
+ to: '2026-04-18T00:00:00Z',
+ },
+ },
+ daily: [
+ {
+ day: '2026-04-18',
+ opened: 2,
+ api_path_selected: 1,
+ agent_path_selected: 0,
+ probe_detected: 1,
+ probe_no_match: 1,
+ probe_error: 0,
+ catalog_selected: 1,
+ credentials_opened: 1,
+ },
+ ],
+ paths: [{ key: 'api', count: 2 }],
+ platforms: [{ key: 'truenas', catalog_selected: 2, credentials_opened: 1 }],
+ notes: ['Some probed addresses did not match a supported API-backed platform.'],
+ },
+ errors: ['probe failed for 10.0.0.10 after timeout'],
+});
+
+describe('diagnosticsModel', () => {
+ it('sanitizes infrastructure diagnostics without stripping onboarding analytics', () => {
+ const raw = createDiagnosticsData();
+
+ const sanitized = sanitizeDiagnosticsData(raw);
+
+ expect(raw.nodes[0].host).toBe('10.0.0.5');
+ expect(sanitized.nodes).toEqual([
+ expect.objectContaining({
+ id: 'node-1',
+ name: 'node-1',
+ host: 'node-1',
+ error: 'dial tcp [REDACTED_IP]:8006: connect: connection refused',
+ }),
+ ]);
+ expect(sanitized.pbs).toEqual([
+ expect.objectContaining({
+ id: 'pbs-1',
+ name: 'pbs-1',
+ host: 'pbs-1',
+ error: 'Get https://[REDACTED_IP]:8007: EOF',
+ }),
+ ]);
+ expect(sanitized.discovery).toEqual(
+ expect.objectContaining({
+ configuredSubnet: '[REDACTED_SUBNET]',
+ activeSubnet: '[REDACTED_SUBNET]',
+ environmentOverride: '[REDACTED]',
+ subnetAllowlist: ['[REDACTED_SUBNET]'],
+ subnetBlocklist: ['[REDACTED_SUBNET]'],
+ history: [
+ expect.objectContaining({
+ subnet: '[REDACTED_SUBNET]',
+ }),
+ ],
+ }),
+ );
+ expect(sanitized.errors).toEqual(['probe failed for [REDACTED_IP] after timeout']);
+ expect(sanitized.infrastructureOnboarding).toEqual(raw.infrastructureOnboarding);
+ });
+
+ it('builds stable diagnostics export filenames', () => {
+ const now = new Date('2026-04-22T12:34:56Z');
+
+ expect(buildDiagnosticsExportFilename(false, now)).toBe('pulse-diagnostics-full-2026-04-22.json');
+ expect(buildDiagnosticsExportFilename(true, now)).toBe(
+ 'pulse-diagnostics-sanitized-2026-04-22.json',
+ );
+ });
+});
diff --git a/frontend-modern/src/components/Settings/__tests__/useDiagnosticsPanelState.test.ts b/frontend-modern/src/components/Settings/__tests__/useDiagnosticsPanelState.test.ts
new file mode 100644
index 0000000000..9de992bc73
--- /dev/null
+++ b/frontend-modern/src/components/Settings/__tests__/useDiagnosticsPanelState.test.ts
@@ -0,0 +1,245 @@
+import { renderHook, waitFor } from '@solidjs/testing-library';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { DiagnosticsData } from '@/components/Settings/diagnosticsModel';
+
+type UseDiagnosticsPanelStateModule = typeof import('../useDiagnosticsPanelState');
+
+const createDiagnosticsData = (): DiagnosticsData => ({
+ version: '6.0.0',
+ runtime: 'go',
+ uptime: 3600,
+ nodes: [
+ {
+ id: 'node-a',
+ name: 'pve-01',
+ host: '10.0.0.5',
+ type: 'pve',
+ authMethod: 'token',
+ connected: false,
+ error: 'dial tcp 10.0.0.5:8006: connect: connection refused',
+ },
+ ],
+ pbs: [],
+ system: {
+ os: 'linux',
+ arch: 'amd64',
+ goVersion: 'go1.25',
+ numCPU: 8,
+ numGoroutine: 32,
+ memoryMB: 128,
+ },
+ discovery: {
+ enabled: true,
+ configuredSubnet: '10.0.0.0/24',
+ activeSubnet: '10.0.1.0/24',
+ environmentOverride: 'PULSE_DISCOVERY_SUBNET=10.0.2.0/24',
+ subnetAllowlist: ['10.0.0.0/24'],
+ subnetBlocklist: [],
+ },
+ infrastructureOnboarding: {
+ enabled: true,
+ status: 'warning',
+ windowDays: 30,
+ summary: {
+ opened: 4,
+ api_path_selected: 2,
+ agent_path_selected: 1,
+ probe_detected: 1,
+ probe_no_match: 2,
+ probe_error: 0,
+ catalog_selected: 2,
+ credentials_opened: 1,
+ period: {
+ from: '2026-03-19T00:00:00Z',
+ to: '2026-04-18T00:00:00Z',
+ },
+ },
+ daily: [],
+ paths: [{ key: 'api', count: 2 }],
+ platforms: [{ key: 'truenas', catalog_selected: 2, credentials_opened: 1 }],
+ notes: ['Some probed addresses did not match a supported API-backed platform.'],
+ },
+ errors: ['probe failed for 10.0.0.10 after timeout'],
+});
+
+const readBlobText = async (blob: Blob): Promise<string> =>
+ await new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.onload = () => resolve(String(reader.result ?? ''));
+ reader.onerror = () => reject(reader.error ?? new Error('Failed to read exported diagnostics'));
+ reader.readAsText(blob);
+ });
+
+const currentExportDate = (): string => new Date().toISOString().split('T')[0];
+
+describe('useDiagnosticsPanelState', () => {
+ let useDiagnosticsPanelState: UseDiagnosticsPanelStateModule['useDiagnosticsPanelState'];
+ let apiFetchJSONMock: ReturnType<typeof vi.fn>;
+ let showErrorMock: ReturnType<typeof vi.fn>;
+ let showSuccessMock: ReturnType<typeof vi.fn>;
+ let createObjectURLMock: ReturnType<typeof vi.fn>;
+ let revokeObjectURLMock: ReturnType<typeof vi.fn>;
+ let anchorClickMock: ReturnType<typeof vi.fn>;
+ let createdAnchor: HTMLAnchorElement | null;
+ let originalCreateObjectURL: typeof URL.createObjectURL | undefined;
+ let originalRevokeObjectURL: typeof URL.revokeObjectURL | undefined;
+
+ beforeEach(async () => {
+ vi.resetModules();
+
+ apiFetchJSONMock = vi.fn();
+ showErrorMock = vi.fn();
+ showSuccessMock = vi.fn();
+ createObjectURLMock = vi.fn(() => 'blob:diagnostics-export');
+ revokeObjectURLMock = vi.fn();
+ anchorClickMock = vi.fn();
+ createdAnchor = null;
+ originalCreateObjectURL = URL.createObjectURL;
+ originalRevokeObjectURL = URL.revokeObjectURL;
+
+ vi.doMock('@/utils/apiClient', () => ({
+ apiFetchJSON: apiFetchJSONMock,
+ }));
+
+ vi.doMock('@/utils/toast', () => ({
+ showError: showErrorMock,
+ showSuccess: showSuccessMock,
+ }));
+
+ Object.defineProperty(URL, 'createObjectURL', {
+ configurable: true,
+ value: createObjectURLMock,
+ });
+ Object.defineProperty(URL, 'revokeObjectURL', {
+ configurable: true,
+ value: revokeObjectURLMock,
+ });
+
+ const createElement = document.createElement.bind(document);
+ vi.spyOn(document, 'createElement').mockImplementation(((tagName: string) => {
+ const element = createElement(tagName);
+ if (tagName.toLowerCase() === 'a') {
+ createdAnchor = element as HTMLAnchorElement;
+ createdAnchor.click = anchorClickMock;
+ }
+ return element;
+ }) as typeof document.createElement);
+
+ ({ useDiagnosticsPanelState } = await import('../useDiagnosticsPanelState'));
+ });
+
+ afterEach(() => {
+ if (originalCreateObjectURL) {
+ Object.defineProperty(URL, 'createObjectURL', {
+ configurable: true,
+ value: originalCreateObjectURL,
+ });
+ } else {
+ delete (URL as URL & { createObjectURL?: typeof URL.createObjectURL }).createObjectURL;
+ }
+ if (originalRevokeObjectURL) {
+ Object.defineProperty(URL, 'revokeObjectURL', {
+ configurable: true,
+ value: originalRevokeObjectURL,
+ });
+ } else {
+ delete (URL as URL & { revokeObjectURL?: typeof URL.revokeObjectURL }).revokeObjectURL;
+ }
+ vi.restoreAllMocks();
+ vi.resetModules();
+ });
+
+ it('exports full diagnostics with infrastructure onboarding analytics intact', async () => {
+ const diagnosticsData = createDiagnosticsData();
+ apiFetchJSONMock.mockResolvedValue(diagnosticsData);
+
+ const { result } = renderHook(() => useDiagnosticsPanelState());
+
+ await result.runDiagnostics();
+
+ await waitFor(() => expect(result.diagnosticsData()).toEqual(diagnosticsData));
+ expect(apiFetchJSONMock).toHaveBeenCalledWith('/api/diagnostics');
+ expect(showSuccessMock).toHaveBeenCalledWith('Diagnostics completed');
+
+ await result.exportDiagnostics(false);
+
+ expect(createObjectURLMock).toHaveBeenCalledOnce();
+ expect(anchorClickMock).toHaveBeenCalledOnce();
+ expect(createdAnchor?.download).toBe(`pulse-diagnostics-full-${currentExportDate()}.json`);
+ expect(revokeObjectURLMock).toHaveBeenCalledWith('blob:diagnostics-export');
+ expect(showSuccessMock).toHaveBeenCalledWith('Diagnostics exported (full)');
+
+ const payload = JSON.parse(
+ await readBlobText(createObjectURLMock.mock.calls[0][0] as Blob),
+ ) as DiagnosticsData;
+
+ expect(payload.infrastructureOnboarding?.summary.credentials_opened).toBe(1);
+ expect(payload.infrastructureOnboarding?.platforms).toEqual([
+ expect.objectContaining({
+ key: 'truenas',
+ catalog_selected: 2,
+ credentials_opened: 1,
+ }),
+ ]);
+ expect(payload.nodes[0].host).toBe('10.0.0.5');
+ });
+
+ it('exports sanitized diagnostics while preserving onboarding funnel counts', async () => {
+ apiFetchJSONMock.mockResolvedValue(createDiagnosticsData());
+
+ const { result } = renderHook(() => useDiagnosticsPanelState());
+
+ await result.runDiagnostics();
+ await waitFor(() => expect(result.diagnosticsData()).not.toBeNull());
+
+ await result.exportDiagnostics(true);
+
+ expect(anchorClickMock).toHaveBeenCalledOnce();
+ expect(createdAnchor?.download).toBe(
+ `pulse-diagnostics-sanitized-${currentExportDate()}.json`,
+ );
+ expect(showSuccessMock).toHaveBeenCalledWith('Diagnostics exported (sanitized)');
+
+ const payload = JSON.parse(
+ await readBlobText(createObjectURLMock.mock.calls[0][0] as Blob),
+ ) as DiagnosticsData;
+
+ expect(payload.nodes[0]).toEqual(
+ expect.objectContaining({
+ id: 'node-1',
+ name: 'node-1',
+ host: 'node-1',
+ }),
+ );
+ expect(payload.discovery).toEqual(
+ expect.objectContaining({
+ configuredSubnet: '[REDACTED_SUBNET]',
+ activeSubnet: '[REDACTED_SUBNET]',
+ }),
+ );
+ expect(payload.errors).toEqual(['probe failed for [REDACTED_IP] after timeout']);
+ expect(payload.infrastructureOnboarding?.summary).toEqual(
+ expect.objectContaining({
+ opened: 4,
+ api_path_selected: 2,
+ credentials_opened: 1,
+ }),
+ );
+ expect(payload.infrastructureOnboarding?.platforms).toEqual([
+ expect.objectContaining({
+ key: 'truenas',
+ catalog_selected: 2,
+ credentials_opened: 1,
+ }),
+ ]);
+ });
+
+ it('blocks export until diagnostics have been run', async () => {
+ const { result } = renderHook(() => useDiagnosticsPanelState());
+
+ await result.exportDiagnostics(true);
+
+ expect(showErrorMock).toHaveBeenCalledWith('Run diagnostics first');
+ expect(createObjectURLMock).not.toHaveBeenCalled();
+ });
+});
diff --git a/tests/integration/README.md b/tests/integration/README.md
index 58f039d0aa..1783405f25 100644
--- a/tests/integration/README.md
+++ b/tests/integration/README.md
@@ -61,6 +61,7 @@ End-to-end Playwright tests that validate critical user flows against a running
- `tests/69-diagnostics-onboarding.spec.ts` — diagnostics onboarding analytics browser proof:
- Proves the Diagnostics & Health page renders the infrastructure onboarding analytics card after a real diagnostics run
- Verifies the shared diagnostics surface shows onboarding path/platform attribution alongside the existing commercial funnel
+ - Verifies the exported full and sanitized diagnostics JSON preserve onboarding analytics while redacting operator-sensitive host/subnet data
- Verifies the populated mobile diagnostics page fits the viewport without horizontal overflow
## Running Tests
diff --git a/tests/integration/tests/69-diagnostics-onboarding.spec.ts b/tests/integration/tests/69-diagnostics-onboarding.spec.ts
index 5b078f7269..91ae4f4c97 100644
--- a/tests/integration/tests/69-diagnostics-onboarding.spec.ts
+++ b/tests/integration/tests/69-diagnostics-onboarding.spec.ts
@@ -198,6 +198,43 @@ const DIAGNOSTICS_PAYLOAD = {
memorySourceBreakdown: [],
};
+const EXPORT_DIAGNOSTICS_PAYLOAD = {
+ ...DIAGNOSTICS_PAYLOAD,
+ nodes: [
+ {
+ id: 'node-raw-id',
+ name: 'pve-01',
+ host: '10.0.0.5',
+ type: 'pve',
+ authMethod: 'token',
+ connected: false,
+ error: 'dial tcp 10.0.0.5:8006: connect: connection refused',
+ },
+ ],
+ discovery: {
+ enabled: true,
+ configuredSubnet: '10.0.0.0/24',
+ activeSubnet: '10.0.1.0/24',
+ environmentOverride: 'PULSE_DISCOVERY_SUBNET=10.0.2.0/24',
+ subnetAllowlist: ['10.0.0.0/24'],
+ subnetBlocklist: ['10.0.3.0/24'],
+ history: [
+ {
+ startedAt: '2026-04-17T10:00:00Z',
+ completedAt: '2026-04-17T10:00:05Z',
+ duration: '5s',
+ durationMs: 5000,
+ subnet: '10.0.0.0/24',
+ serverCount: 3,
+ errorCount: 1,
+ blocklistLength: 1,
+ status: 'completed',
+ },
+ ],
+ },
+ errors: ['probe failed for 10.0.0.10 after timeout'],
+};
+
const test = base.extend<{}, WorkerFixtures>({
storageState: async ({ authStorageStatePath }, use) => {
await use(authStorageStatePath);
@@ -221,7 +258,10 @@ const test = base.extend<{}, WorkerFixtures>({
}, { scope: 'worker' }],
});
-async function prepareDiagnosticsRoute(page: Page): Promise<void> {
+async function prepareDiagnosticsRoute(
+ page: Page,
+ payload = DIAGNOSTICS_PAYLOAD,
+): Promise<void> {
await page.route('**/api/diagnostics', async (route) => {
const requestUrl = new URL(route.request().url());
if (route.request().method() !== 'GET' || requestUrl.pathname !== '/api/diagnostics') {
@@ -232,7 +272,7 @@ async function prepareDiagnosticsRoute(page: Page): Promise<void> {
await route.fulfill({
status: 200,
contentType: 'application/json',
- body: JSON.stringify(DIAGNOSTICS_PAYLOAD),
+ body: JSON.stringify(payload),
});
});
}
@@ -321,6 +361,80 @@ test.describe('Diagnostics onboarding analytics', () => {
).toBeVisible();
});
+ test('desktop diagnostics exports full and sanitized onboarding analytics JSON', async ({
+ page,
+ }, testInfo) => {
+ test.skip(testInfo.project.name.startsWith('mobile-'), 'Desktop-only diagnostics export coverage');
+
+ await prepareDiagnosticsRoute(page, EXPORT_DIAGNOSTICS_PAYLOAD);
+
+ await page.goto('/settings/support/diagnostics', { waitUntil: 'domcontentloaded' });
+ await page.waitForURL(/\/settings\/support\/diagnostics$/, { timeout: 15_000 });
+
+ await page.getByRole('button', { name: 'Run Diagnostics', exact: true }).first().click();
+ await expect(page.getByText('Infrastructure Onboarding', { exact: true })).toBeVisible();
+
+ const [fullDownload] = await Promise.all([
+ page.waitForEvent('download'),
+ page.getByRole('button', { name: 'Full', exact: true }).click(),
+ ]);
+
+ expect(fullDownload.suggestedFilename()).toMatch(
+ new RegExp(`^pulse-diagnostics-full-${new Date().toISOString().slice(0, 10)}\\.json$`),
+ );
+
+ const fullPath = await fullDownload.path();
+ expect(fullPath).not.toBeNull();
+ const fullPayload = JSON.parse(fs.readFileSync(fullPath!, 'utf8')) as typeof EXPORT_DIAGNOSTICS_PAYLOAD;
+
+ expect(fullPayload.nodes[0]?.host).toBe('10.0.0.5');
+ expect(fullPayload.discovery?.configuredSubnet).toBe('10.0.0.0/24');
+ expect(fullPayload.infrastructureOnboarding?.summary.credentials_opened).toBe(1);
+ expect(fullPayload.infrastructureOnboarding?.platforms).toEqual([
+ expect.objectContaining({
+ key: 'truenas',
+ catalog_selected: 2,
+ credentials_opened: 1,
+ }),
+ ]);
+
+ const [sanitizedDownload] = await Promise.all([
+ page.waitForEvent('download'),
+ page.getByRole('button', { name: 'GitHub', exact: true }).click(),
+ ]);
+
+ expect(sanitizedDownload.suggestedFilename()).toMatch(
+ new RegExp(`^pulse-diagnostics-sanitized-${new Date().toISOString().slice(0, 10)}\\.json$`),
+ );
+
+ const sanitizedPath = await sanitizedDownload.path();
+ expect(sanitizedPath).not.toBeNull();
+ const sanitizedPayload = JSON.parse(fs.readFileSync(sanitizedPath!, 'utf8')) as typeof EXPORT_DIAGNOSTICS_PAYLOAD;
+
+ expect(sanitizedPayload.nodes[0]).toEqual(
+ expect.objectContaining({
+ id: 'node-1',
+ name: 'node-1',
+ host: 'node-1',
+ }),
+ );
+ expect(sanitizedPayload.discovery).toEqual(
+ expect.objectContaining({
+ configuredSubnet: '[REDACTED_SUBNET]',
+ activeSubnet: '[REDACTED_SUBNET]',
+ environmentOverride: '[REDACTED]',
+ }),
+ );
+ expect(sanitizedPayload.errors).toEqual(['probe failed for [REDACTED_IP] after timeout']);
+ expect(sanitizedPayload.infrastructureOnboarding?.summary).toEqual(
+ expect.objectContaining({
+ opened: 4,
+ api_path_selected: 2,
+ credentials_opened: 1,
+ }),
+ );
+ });
+
test('mobile diagnostics keeps the populated onboarding analytics page inside the viewport', async ({
page,
}, testInfo) => {