Secrets: grant access from the secret's detail card (ENB-20)
CI / integration (push) Failing after 12s
CI / check (push) Successful in 16s

Adds a Grant access button to the selected secret. An inline form picks an
identity (user, entity or group), whether to grant just this secret or its
whole folder, and capabilities; the access table refreshes afterwards.

- Extract CapabilityPicker and useRefreshAccess from the Access editor so both
  grant forms share them.
- Stop Enter on the identity and engine dropdowns from submitting the form,
  which could grant access by accident.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-10-20 13:48:07 +01:00
1 parent 61bb6d912a
commit 791cf9603a
8 files changed
+287 -26

No files matched your search

+55
View File
@@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event'
import { MemoryRouter } from 'react-router'
import { afterEach, beforeEach, expect, test, vi } from 'vitest'
import { BaoClient } from '../../api/bao'
import * as grants from '../../api/grants'
import * as ids from '../../api/identities'
import * as api from '../../api/secrets'
import { SessionProvider } from '../../api/session'
@@ -11,6 +12,7 @@ import { useSession } from '../../api/useSession'
import * as tokens from '../../api/tokens'
import { SecretsPage } from './SecretsPage'
vi.mock('../../api/grants')
vi.mock('../../api/identities')
vi.mock('../../api/secrets', async (orig) => ({ ...(await orig<typeof api>()), listKvMounts: vi.fn(), listSecrets: vi.fn(), readPolicyHcl: vi.fn() }))
vi.mock('../../api/tokens')
@@ -72,6 +74,59 @@ test('navigates folders and shows who can reach a secret', async () => {
expect(within(panel).getByText('secret/data/app/db')).toBeInTheDocument()
})
async function openSecret() {
render(
<QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>
<SessionProvider>
<MemoryRouter>
<Connected />
<SecretsPage />
</MemoryRouter>
</SessionProvider>
</QueryClientProvider>,
)
const user = userEvent.setup()
await user.click(screen.getByRole('button', { name: 'go' }))
await user.click(await screen.findByRole('button', { name: /app\// }))
await user.click(await screen.findByRole('button', { name: /db/ }))
await user.click(await screen.findByRole('button', { name: 'Grant access' }))
return user
}
test('grants an identity access to the open secret', async () => {
vi.mocked(grants.grantAccess).mockResolvedValue()
const user = await openSecret()
await user.selectOptions(screen.getByLabelText('Who'), 'bob')
await user.click(screen.getByLabelText('update'))
await user.click(screen.getByRole('button', { name: 'Grant' }))
expect(grants.grantAccess).toHaveBeenCalledWith(client, { kind: 'user', name: 'bob' }, [
{ path: 'secret/data/app/db', capabilities: ['read', 'update'] },
{ path: 'secret/metadata/app/db', capabilities: [] },
])
expect(await screen.findByRole('status')).toHaveTextContent('Granted read, update on secret/app/db to user “bob”.')
expect(screen.queryByRole('form', { name: 'Grant access to this secret' })).not.toBeInTheDocument()
})
test('can grant the whole folder instead of just the secret', async () => {
vi.mocked(grants.grantAccess).mockResolvedValue()
const user = await openSecret()
await user.click(screen.getByLabelText(/Everything in/))
await user.click(screen.getByRole('button', { name: 'Grant' }))
expect(grants.grantAccess).toHaveBeenCalledWith(client, { kind: 'user', name: 'alice' }, [
{ path: 'secret/data/app/*', capabilities: ['read'] },
{ path: 'secret/metadata/app/*', capabilities: [] },
])
})
test('shows why a grant failed and keeps the form open', async () => {
vi.mocked(grants.grantAccess).mockRejectedValue(new Error('Policy "envbao-user-alice" was edited outside EnvBao'))
const user = await openSecret()
await user.click(screen.getByRole('button', { name: 'Grant' }))
expect(await screen.findByRole('alert')).toHaveTextContent('edited outside EnvBao')
expect(screen.getByRole('form', { name: 'Grant access to this secret' })).toBeInTheDocument()
})
test('asks to connect first', () => {
render(
<QueryClientProvider client={new QueryClient()}>