Config: show each database connection's URL and allowed roles

The connections table reads each connection and lists its URL and
allowed roles. Literal passwords in a URL are masked; templated
{{password}} URLs are shown as-is.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-11-09 14:09:42 +00:00
1 parent 44e4eb75c9
commit fd20caa525
4 files changed
+116 -9

No files matched your search

+39 -1
View File
@@ -1,5 +1,5 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen } from '@testing-library/react'
import { render, screen, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { afterEach, beforeEach, expect, test, vi } from 'vitest'
import { BaoClient } from '../../api/bao'
@@ -95,3 +95,41 @@ test('shows the load error', async () => {
renderPanel('database')
expect(await screen.findByRole('alert')).toHaveTextContent('permission denied')
})
test('the connections table shows each connection\'s URL and allowed roles, hiding literal passwords', async () => {
vi.mocked(config.listConfigs).mockResolvedValue(['main', 'legacy', 'bare'])
vi.mocked(config.readConfig).mockImplementation(async (_c, _m, _k, name) =>
name === 'main'
? { connection_url: 'postgresql://{{username}}:{{password}}@db:5432/app', allowed_roles: ['readonly', 'readwrite'] }
: name === 'legacy'
? { connection_url: 'postgresql://bao:hunter2@old:5432/app', allowed_roles: ['*'] }
: { allowed_roles: [] },
)
renderPanel('database')
const table = await screen.findByRole('table', { name: 'Connections' })
expect(within(table).getAllByRole('columnheader').map((h) => h.textContent)).toEqual(['Name', 'Connection URL', 'Allowed roles', ''])
const main = (await within(table).findByText('main')).closest('tr')!
expect(await within(main).findByText('postgresql://{{username}}:{{password}}@db:5432/app')).toBeInTheDocument()
expect(within(main).getByText('readonly')).toBeInTheDocument()
expect(within(main).getByText('readwrite')).toBeInTheDocument()
const legacy = within(table).getByText('legacy').closest('tr')!
expect(await within(legacy).findByText('postgresql://bao:••••@old:5432/app')).toBeInTheDocument()
expect(table).not.toHaveTextContent('hunter2')
expect(within(legacy).getByText('*')).toBeInTheDocument()
const bare = within(table).getByText('bare').closest('tr')!
expect((await within(bare).findAllByText('None')).length).toBe(2)
})
test('a connection that cannot be read says why, without hiding the others', async () => {
vi.mocked(config.listConfigs).mockResolvedValue(['ok', 'broken'])
vi.mocked(config.readConfig).mockImplementation(async (_c, _m, _k, name) => {
if (name === 'broken') throw new Error('permission denied')
return { connection_url: 'postgresql://db/app', allowed_roles: ['ro'] }
})
renderPanel('database')
expect(await screen.findByText('postgresql://db/app')).toBeInTheDocument()
expect(await screen.findByRole('alert')).toHaveTextContent('permission denied')
})