Files
supabase/apps/studio/components/interfaces/Auth/OAuthApps/NewOAuthAppModal.test.tsx
Drew McLellan 2c871b42b7 fix(studio): show OAuth app client secret in a blocking modal (#53167)
## Problem

After creating a confidential OAuth app or regenerating its client
secret, the credentials appeared in a small dismissible banner above the
apps table. The secret can't be retrieved again, so a missed banner
meant regenerating the secret and breaking existing integrations.

## Change

- Replace `NewOAuthAppBanner` with `NewOAuthAppModal`, following the
pattern of the S3 access key `CreateCredentialModal`.
- The modal shows the client ID and client secret with copy buttons and
states the secret won't be shown again.
- It can only be closed with Done. Outside clicks, Escape and the close
button are blocked.
- Public apps (no client secret) and plain edits behave as before: no
modal.
- Create and both regenerate entry points (row menu and sheet) feed the
same modal, so no data-layer changes.

Step 1:
<img width="420" height="251" alt="Image"
src="https://github.com/user-attachments/assets/74430837-90fd-49e9-9441-234abc97588a"
/>

Step 2:
<img width="420" height="375" alt="Image"
src="https://github.com/user-attachments/assets/92ab3786-8bd1-46cf-a4b4-b2643f288e65"
/>

## Testing

- Added `NewOAuthAppModal.test.tsx`: credentials and warning render, no
modal for public or missing apps, only Done dismisses.
- Manual: Authentication → OAuth Apps → create a confidential app, and
regenerate from the row menu and the sheet.

Closes #53116
Linear: FE-4976
2026-11-09 16:30:11 +00:00

50 lines
1.8 KiB
TypeScript

import type { OAuthClient } from '@supabase/supabase-js'
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { describe, expect, test, vi } from 'vitest'
import { NewOAuthAppModal } from './NewOAuthAppModal'
import { customRender } from '@/tests/lib/custom-render'
const confidentialApp = {
client_id: 'client-id-123',
client_secret: 'secret-abc',
client_name: 'My App',
} as OAuthClient
describe('NewOAuthAppModal', () => {
test('shows the credentials and a warning that the secret is shown once', () => {
customRender(<NewOAuthAppModal oauthApp={confidentialApp} onClose={vi.fn()} />)
expect(screen.getByDisplayValue('client-id-123')).toBeInTheDocument()
expect(screen.getByDisplayValue('secret-abc')).toBeInTheDocument()
expect(screen.getByText(/won't be shown again/)).toBeInTheDocument()
})
test('does not render for a public app without a client secret', () => {
const publicApp = { ...confidentialApp, client_secret: undefined } as OAuthClient
customRender(<NewOAuthAppModal oauthApp={publicApp} onClose={vi.fn()} />)
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
})
test('does not render when there is no app', () => {
customRender(<NewOAuthAppModal oauthApp={undefined} onClose={vi.fn()} />)
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
})
test('can only be dismissed with the Done button', async () => {
const user = userEvent.setup({ pointerEventsCheck: 0 })
const onClose = vi.fn()
customRender(<NewOAuthAppModal oauthApp={confidentialApp} onClose={onClose} />)
await user.keyboard('{Escape}')
await user.click(document.body)
expect(onClose).not.toHaveBeenCalled()
await user.click(screen.getByRole('button', { name: 'Done' }))
expect(onClose).toHaveBeenCalledTimes(1)
})
})