mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem SSL enforcement currently warns that the database will be restarted. This is no longer the case. ## Solution SSL enforcement no longer restarts the database. Update references to indicate that only non-SSL enabled connections are disabled. Only display warning when enabling SSL enforcement. ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
197 lines
7.1 KiB
TypeScript
197 lines
7.1 KiB
TypeScript
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import type { components, paths } from 'api-types'
|
|
import { HttpResponse } from 'msw'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { SSLConfiguration } from './SSLConfiguration'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
type ProjectSettingsResponse = components['schemas']['ProjectSettingsResponse_Output']
|
|
type SslEnforcementResponse = components['schemas']['SslEnforcementResponse_Output']
|
|
type JitAccessConfigResponse =
|
|
paths['/v1/projects/{ref}/jit-access']['get']['responses'][200]['content']['application/json']
|
|
|
|
const { mockUseAsyncCheckPermissions, mockUseHighAvailability, mockUseSelectedProjectQuery } =
|
|
vi.hoisted(() => ({
|
|
mockUseAsyncCheckPermissions: vi.fn(),
|
|
mockUseHighAvailability: vi.fn(),
|
|
mockUseSelectedProjectQuery: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/hooks/misc/useCheckPermissionsV2', () => ({
|
|
useAsyncCheckPermissionsV2: mockUseAsyncCheckPermissions,
|
|
FGA_PERMISSIONS: { PROJECT: { DATABASE_SSL_CONFIG_WRITE: 'database_ssl_config_write' } },
|
|
}))
|
|
|
|
vi.mock('@/hooks/misc/useHighAvailability', () => ({
|
|
useHighAvailability: mockUseHighAvailability,
|
|
}))
|
|
|
|
vi.mock('@/hooks/misc/useSelectedProject', () => ({
|
|
useSelectedProjectQuery: mockUseSelectedProjectQuery,
|
|
}))
|
|
|
|
const HA_TOOLTIP = 'SSL is always enforced on High Availability projects'
|
|
|
|
function mockProjectSettings() {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/settings',
|
|
response: () =>
|
|
HttpResponse.json<ProjectSettingsResponse>({
|
|
app_config: {
|
|
db_schema: 'public',
|
|
endpoint: 'default.supabase.co',
|
|
storage_endpoint: 'storage.default.supabase.co',
|
|
},
|
|
cloud_provider: 'AWS',
|
|
db_dns_name: 'default.supabase.co',
|
|
db_host: 'default.supabase.co',
|
|
db_ip_addr_config: 'ipv4',
|
|
db_name: 'postgres',
|
|
db_port: 5432,
|
|
db_user: 'postgres',
|
|
inserted_at: '2025-02-16T22:24:42.115195',
|
|
name: 'default',
|
|
ref: 'default',
|
|
region: 'us-east-1',
|
|
ssl_enforced: true,
|
|
status: 'ACTIVE_HEALTHY',
|
|
}),
|
|
})
|
|
}
|
|
|
|
function mockJitDbAccess() {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/v1/projects/:ref/jit-access',
|
|
response: () =>
|
|
HttpResponse.json<JitAccessConfigResponse>({ state: 'disabled', appliedSuccessfully: true }),
|
|
})
|
|
}
|
|
|
|
/** Registers the SSL enforcement GET and returns a counter of how often it was hit. */
|
|
function mockSSLEnforcement(config: SslEnforcementResponse) {
|
|
const requests = { count: 0 }
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/v1/projects/:ref/ssl-enforcement',
|
|
response: () => {
|
|
requests.count += 1
|
|
return HttpResponse.json<SslEnforcementResponse>(config)
|
|
},
|
|
})
|
|
return requests
|
|
}
|
|
|
|
describe('SSLConfiguration', () => {
|
|
beforeEach(() => {
|
|
mockUseSelectedProjectQuery.mockReturnValue({ data: { id: 1, ref: 'default' } })
|
|
mockUseAsyncCheckPermissions.mockReturnValue({ can: true })
|
|
mockProjectSettings()
|
|
mockJitDbAccess()
|
|
})
|
|
|
|
it('shows SSL enforcement as always on for High Availability projects', async () => {
|
|
mockUseHighAvailability.mockReturnValue({ isHighAvailability: true, isPending: false })
|
|
const sslEnforcementRequests = mockSSLEnforcement({
|
|
appliedSuccessfully: true,
|
|
currentConfig: { database: false },
|
|
})
|
|
|
|
customRender(<SSLConfiguration />)
|
|
|
|
const sslSwitch = await screen.findByRole('switch')
|
|
expect(sslSwitch).toBeChecked()
|
|
expect(sslSwitch).toBeDisabled()
|
|
// Nothing is loading for HA projects, so there is no announcement to make
|
|
expect(screen.getByRole('status')).toBeEmptyDOMElement()
|
|
|
|
// The tooltip trigger is the wrapper around the (disabled) switch. Focus opens a Radix
|
|
// tooltip without the hover delay.
|
|
fireEvent.focus(sslSwitch.parentElement!)
|
|
expect((await screen.findAllByText(HA_TOOLTIP)).length).toBeGreaterThan(0)
|
|
|
|
expect(sslEnforcementRequests.count).toBe(0)
|
|
})
|
|
|
|
it('does not open the confirm dialog around a disabled switch on High Availability projects', async () => {
|
|
mockUseHighAvailability.mockReturnValue({ isHighAvailability: true, isPending: false })
|
|
mockSSLEnforcement({ appliedSuccessfully: true, currentConfig: { database: false } })
|
|
|
|
customRender(<SSLConfiguration />)
|
|
|
|
const sslSwitch = await screen.findByRole('switch')
|
|
// Clicking the disabled switch and the row wrapper around it must not open the dialog
|
|
await userEvent.click(sslSwitch)
|
|
await userEvent.click(sslSwitch.parentElement!.parentElement!)
|
|
|
|
expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('reflects the fetched SSL enforcement config for other projects', async () => {
|
|
mockUseHighAvailability.mockReturnValue({ isHighAvailability: false, isPending: false })
|
|
const sslEnforcementRequests = mockSSLEnforcement({
|
|
appliedSuccessfully: true,
|
|
currentConfig: { database: false },
|
|
})
|
|
|
|
customRender(<SSLConfiguration />)
|
|
|
|
const sslSwitch = await screen.findByRole('switch')
|
|
expect(sslSwitch).not.toBeChecked()
|
|
expect(sslSwitch).toBeEnabled()
|
|
expect(screen.getByRole('status')).toBeEmptyDOMElement()
|
|
expect(sslEnforcementRequests.count).toBe(1)
|
|
})
|
|
|
|
it('opens the confirm dialog from the switch and leaves it unchanged on cancel', async () => {
|
|
mockUseHighAvailability.mockReturnValue({ isHighAvailability: false, isPending: false })
|
|
mockSSLEnforcement({ appliedSuccessfully: true, currentConfig: { database: false } })
|
|
|
|
customRender(<SSLConfiguration />)
|
|
|
|
const sslSwitch = await screen.findByRole('switch')
|
|
await userEvent.click(sslSwitch)
|
|
|
|
const dialog = await screen.findByRole('alertdialog')
|
|
expect(dialog).toHaveTextContent('Enforce SSL on connections?')
|
|
expect(screen.getByRole('button', { name: 'Enforce SSL' })).toBeInTheDocument()
|
|
// Controlled switch must not flip while the dialog is open
|
|
expect(sslSwitch).not.toBeChecked()
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: 'Cancel' }))
|
|
|
|
await waitFor(() => expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument())
|
|
expect(sslSwitch).not.toBeChecked()
|
|
})
|
|
|
|
it('disables SSL enforcement without a confirm dialog', async () => {
|
|
mockUseHighAvailability.mockReturnValue({ isHighAvailability: false, isPending: false })
|
|
mockSSLEnforcement({ appliedSuccessfully: true, currentConfig: { database: true } })
|
|
const updateRequests: unknown[] = []
|
|
addAPIMock({
|
|
method: 'put',
|
|
path: '/v1/projects/:ref/ssl-enforcement',
|
|
response: async ({ request }) => {
|
|
updateRequests.push(await request.json())
|
|
return HttpResponse.json<SslEnforcementResponse>({
|
|
appliedSuccessfully: true,
|
|
currentConfig: { database: false },
|
|
})
|
|
},
|
|
})
|
|
|
|
customRender(<SSLConfiguration />)
|
|
|
|
const sslSwitch = await screen.findByRole('switch')
|
|
expect(sslSwitch).toBeChecked()
|
|
await userEvent.click(sslSwitch)
|
|
|
|
await waitFor(() => expect(updateRequests).toEqual([{ requestedConfig: { database: false } }]))
|
|
expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument()
|
|
})
|
|
})
|