mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
feat(server): validate notification request bodies
notifications.dto.ts wraps the @trek/shared request schemas via createZodDto and types all five @Body() params; the five NotificationsController entries leave the body-contract allow-list (ratchet gate enforced). Contract catch: the client sends server/token: null on test-ntfy to mean 'use the saved value', so testNtfyRequestSchema gains .nullable() there (spec pinned). The inline response-enum and url-type checks die — malformed bodies now get the pipe's standard envelope; valid bodies behave byte-identically. Two integration cases pinning pre-ratchet tolerances (flat notify_* preferences body, body-less test-smtp POST) update to the current wire contract.
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
notificationRespondRequestSchema,
|
||||
channelTestResultSchema,
|
||||
inAppListResultSchema,
|
||||
testNtfyRequestSchema,
|
||||
} from './notification.schema';
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
@@ -29,6 +30,14 @@ describe('notificationRespondRequestSchema', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('testNtfyRequestSchema', () => {
|
||||
it('accepts null server/token — the client sends null to mean "use the saved value"', () => {
|
||||
expect(testNtfyRequestSchema.safeParse({ topic: 't', server: null, token: null }).success).toBe(true);
|
||||
expect(testNtfyRequestSchema.safeParse({}).success).toBe(true);
|
||||
expect(testNtfyRequestSchema.safeParse({ topic: 1 }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('channelTestResultSchema', () => {
|
||||
it('accepts a success result and an error result', () => {
|
||||
expect(channelTestResultSchema.safeParse({ success: true }).success).toBe(true);
|
||||
|
||||
@@ -21,10 +21,13 @@ export const testSmtpRequestSchema = z.object({ email: z.string().optional() });
|
||||
export const testWebhookRequestSchema = z.object({
|
||||
url: z.string().optional(),
|
||||
});
|
||||
// server/token are nullable: the client deliberately sends null to mean
|
||||
// "fall back to the saved value" (a stored token is only masked in the
|
||||
// placeholder — sending null keeps the saved one).
|
||||
export const testNtfyRequestSchema = z.object({
|
||||
topic: z.string().optional(),
|
||||
server: z.string().optional(),
|
||||
token: z.string().optional(),
|
||||
server: z.string().nullable().optional(),
|
||||
token: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
/** Result of a channel test ping. */
|
||||
|
||||
Reference in New Issue
Block a user