mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
feat(notifications): Web Push delivers notifications to every device, even with TREK closed
A fourth built-in channel next to email, webhook and ntfy. Browsers register per device, the server encrypts per RFC 8291 and signs per RFC 8292 with node:crypto and sends only to known push services through the SSRF guard. The event matrix decides per category what arrives by push; admins switch the channel on under Notifications. VAPID keys come from the environment or are generated once, only while neither stored row exists, and kept encrypted. A pair that does not decrypt or match is never overwritten and never swapped for another one: push stays off with an error in the log and every device stays registered until the key is fixed. The subject is VAPID_SUBJECT, then an https APP_URL, then the project URL. Only chat messages collapse into one notification per trip, and a replacement still alerts. A 403 removes a device only after three failures in a row; 404 and 410 remove it at once. Password change, reset and an admin setting a password drop the user's devices with the other credentials. The request log redacts subscriptions and endpoints, boot errors print *** for every secret variable, and logout forgets the device with a plain fetch so an expired session cannot redirect midway. Addresses discussion #894.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-MOB-ANOTIF-001 to FE-MOB-ANOTIF-031
|
||||
// FE-MOB-ANOTIF-001 to FE-MOB-ANOTIF-035
|
||||
import { useState } from 'react';
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
@@ -558,4 +558,38 @@ describe('MAdminNotificationsSection', () => {
|
||||
await waitFor(() => expect(bodies).toHaveLength(1));
|
||||
expect(bodies[0].smtp_pass).toBe('hunter2');
|
||||
});
|
||||
|
||||
it('FE-MOB-ANOTIF-033: Web Push has its own card between Ntfy and In-App', () => {
|
||||
render(<Harness initial={{ notification_channels: 'email' }} />);
|
||||
|
||||
const switches = screen.getAllByRole('switch').map((el) => el.getAttribute('aria-label'));
|
||||
expect(switches.indexOf('Web Push')).toBe(switches.indexOf('Ntfy') + 1);
|
||||
expect(switches.indexOf('In-App')).toBe(switches.indexOf('Web Push') + 1);
|
||||
expect(screen.getByText(/receive notifications on their phones/)).toBeInTheDocument();
|
||||
expect(screen.getByRole('switch', { name: 'Web Push' })).toHaveAttribute('aria-checked', 'false');
|
||||
});
|
||||
|
||||
it('FE-MOB-ANOTIF-034: switching Web Push on saves the list and keeps unknown ids', async () => {
|
||||
const bodies = captureAppSettings();
|
||||
const user = userEvent.setup();
|
||||
render(<Harness initial={{ notification_channels: 'webhook,pushover' }} />);
|
||||
|
||||
await user.click(screen.getByRole('switch', { name: 'Web Push' }));
|
||||
|
||||
await waitFor(() => expect(bodies).toHaveLength(1));
|
||||
expect(bodies[0]).toEqual({ notification_channels: 'webhook,push,pushover' });
|
||||
expect(screen.getByRole('switch', { name: 'Web Push' })).toHaveAttribute('aria-checked', 'true');
|
||||
});
|
||||
|
||||
it('FE-MOB-ANOTIF-035: a failed Web Push save rolls the switch back', async () => {
|
||||
failAppSettings();
|
||||
const toast = buildToast();
|
||||
const user = userEvent.setup();
|
||||
render(<Harness initial={{ notification_channels: 'push' }} toast={toast} />);
|
||||
|
||||
await user.click(screen.getByRole('switch', { name: 'Web Push' }));
|
||||
|
||||
await waitFor(() => expect(toast.error).toHaveBeenCalledWith('Error'));
|
||||
expect(screen.getByRole('switch', { name: 'Web Push' })).toHaveAttribute('aria-checked', 'true');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user