mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 12:55:06 +03:00
## What kind of change does this PR introduce? Bug fix. ## What is the current behavior? Webhook endpoint validation is inconsistent across Studio forms. The webhook sheet accepts incomplete hostnames like `https://webhook`, event type validation is not surfaced clearly, and HTTP endpoint validation differs between webhooks, log drains, cron jobs, and database hooks. ## What is the new behavior? - Tightens webhook endpoint URL validation and rejects incomplete hostnames while still allowing localhost and IP-based endpoints. - Surfaces the Event types validation through the standard form error styling and highlights the existing accordion item border when invalid. - **Extracts a shared HTTP endpoint URL validator and reuses it in webhooks, log drains, cron jobs, and database hooks.** - Adds focused regression tests for the webhook sheet and the shared/consumer validation paths. | After | | --- | | <img width="1728" height="997" alt="Webhooks Settings AWS Healthy Toolshed Supabase-CB0D999C-D0BF-47AA-A10F-342A2E328DF9" src="https://github.com/user-attachments/assets/bcbe4876-f9a7-497a-b288-460087a65546" /> | ## To test Form behaviour (in particular URL validation) on: - Webhook endpoint - Log drains - Cron jobs - Database hooks
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { FormSchema } from './EditHookPanel.constants'
|
|
|
|
describe('EditHookPanel FormSchema', () => {
|
|
it('rejects incomplete http_request hostnames', () => {
|
|
const result = FormSchema.safeParse({
|
|
name: 'Test hook',
|
|
table_id: 'public.messages',
|
|
http_method: 'POST' as const,
|
|
timeout_ms: 1000,
|
|
events: ['INSERT'],
|
|
httpHeaders: [],
|
|
httpParameters: [],
|
|
function_type: 'http_request' as const,
|
|
http_url: 'https://webhook',
|
|
})
|
|
|
|
expect(result.success).toBe(false)
|
|
if (!result.success) {
|
|
expect(
|
|
result.error.issues.some((issue) => issue.message === 'Please provide a valid URL')
|
|
).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('rejects http_request URLs without an explicit protocol', () => {
|
|
const result = FormSchema.safeParse({
|
|
name: 'Test hook',
|
|
table_id: 'public.messages',
|
|
http_method: 'POST' as const,
|
|
timeout_ms: 1000,
|
|
events: ['INSERT'],
|
|
httpHeaders: [],
|
|
httpParameters: [],
|
|
function_type: 'http_request' as const,
|
|
http_url: 'hooks.example.com/webhook',
|
|
})
|
|
|
|
expect(result.success).toBe(false)
|
|
if (!result.success) {
|
|
expect(
|
|
result.error.issues.some(
|
|
(issue) => issue.message === 'Please prefix your URL with http:// or https://'
|
|
)
|
|
).toBe(true)
|
|
}
|
|
})
|
|
})
|