Hardening: session expiry and sealed handling, request timeout, list states, a11y, tested admin policy, security headers, README
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
265c618884
commit
a63f7c0faa
30 files changed
+623
-76
No files matched your search
@@ -47,7 +47,7 @@ test('shows managed grants and read-only other policies', async () => {
|
||||
const user = setup()
|
||||
expect(await screen.findByText('secret/data/app/*')).toBeInTheDocument()
|
||||
const other = screen.getByText('default').closest('li')!
|
||||
await user.click(within(other).getByRole('button', { name: 'View' }))
|
||||
await user.click(within(other).getByRole('button', { name: 'View default' }))
|
||||
expect(await within(other).findByText(/capabilities/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -76,9 +76,9 @@ test('revoke asks for confirmation', async () => {
|
||||
vi.mocked(grants.revokeAccess).mockResolvedValue()
|
||||
const user = setup()
|
||||
const confirm = vi.spyOn(window, 'confirm').mockReturnValueOnce(false).mockReturnValueOnce(true)
|
||||
await user.click(await screen.findByRole('button', { name: 'Revoke' }))
|
||||
await user.click(await screen.findByRole('button', { name: 'Revoke secret/data/app/*' }))
|
||||
expect(grants.revokeAccess).not.toHaveBeenCalled()
|
||||
await user.click(screen.getByRole('button', { name: 'Revoke' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Revoke secret/data/app/*' }))
|
||||
expect(grants.revokeAccess).toHaveBeenCalledWith(client, target, ['secret/data/app/*'])
|
||||
confirm.mockRestore()
|
||||
})
|
||||
@@ -89,7 +89,7 @@ test('a policy edited outside EnvBao is read-only', async () => {
|
||||
)
|
||||
setup()
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('changed outside EnvBao')
|
||||
expect(screen.getByRole('button', { name: 'Revoke' })).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: 'Revoke x' })).toBeDisabled()
|
||||
expect(screen.queryByRole('form', { name: 'Grant access' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ function PolicyView({ client, name }: { client: BaoClient; name: string }) {
|
||||
return (
|
||||
<li>
|
||||
{name}{' '}
|
||||
<button type="button" aria-expanded={open} onClick={() => setOpen(!open)}>
|
||||
<button type="button" aria-label={`${open ? 'Hide' : 'View'} ${name}`} aria-expanded={open} onClick={() => setOpen(!open)}>
|
||||
{open ? 'Hide' : 'View'}
|
||||
</button>
|
||||
{open && <pre>{hcl.isPending ? 'Loading…' : (hcl.data ?? 'Could not read this policy.')}</pre>}
|
||||
@@ -82,7 +82,7 @@ export function AccessEditor({ client, target, onClose }: Props) {
|
||||
</p>
|
||||
)}
|
||||
{s.managed?.grants.length ? (
|
||||
<table>
|
||||
<table aria-label="Granted by EnvBao">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Path</th>
|
||||
@@ -100,6 +100,7 @@ export function AccessEditor({ client, target, onClose }: Props) {
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Revoke ${g.path}`}
|
||||
disabled={!editable}
|
||||
onClick={() => window.confirm(`Revoke ${g.capabilities.join(', ')} on ${g.path}?`) && revoke.mutate(g.path)}
|
||||
>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterEach, expect, test, vi } from 'vitest'
|
||||
import { SessionProvider } from '../../api/session'
|
||||
import { Providers } from '../../test/providers'
|
||||
import { ConnectPage } from './ConnectPage'
|
||||
|
||||
const health = { initialized: true, sealed: false, standby: false, version: '2.1.0' }
|
||||
@@ -11,9 +12,11 @@ afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
function setup() {
|
||||
render(
|
||||
<SessionProvider>
|
||||
<ConnectPage />
|
||||
</SessionProvider>,
|
||||
<Providers>
|
||||
<SessionProvider>
|
||||
<ConnectPage />
|
||||
</SessionProvider>
|
||||
</Providers>,
|
||||
)
|
||||
return userEvent.setup()
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import { useSession } from '../../api/useSession'
|
||||
type Mode = 'token' | 'userpass'
|
||||
|
||||
export function ConnectPage() {
|
||||
const { client, tokenInfo, connect, disconnect } = useSession()
|
||||
const [url, setUrl] = useState(client?.baseUrl ?? 'http://127.0.0.1:8200')
|
||||
const { client, tokenInfo, lastUrl, connect, disconnect } = useSession()
|
||||
const [url, setUrl] = useState(client?.baseUrl ?? lastUrl ?? 'http://127.0.0.1:8200')
|
||||
const [mode, setMode] = useState<Mode>('token')
|
||||
const [token, setToken] = useState('')
|
||||
const [username, setUsername] = useState('')
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useState, type FormEvent } from 'react'
|
||||
import type { BaoClient } from '../../api/bao'
|
||||
import { addAlias, deleteAlias, deleteEntity, listEntities, saveEntity, userpassAccessor, type Entity } from '../../api/identities'
|
||||
import { AccessEditor } from '../access/AccessEditor'
|
||||
import { ListState } from '../shared/ListState'
|
||||
import { PolicyPicker } from '../shared/PolicyPicker'
|
||||
|
||||
interface Draft {
|
||||
@@ -55,8 +56,9 @@ export function EntitiesTab({ client }: { client: BaoClient }) {
|
||||
|
||||
return (
|
||||
<section>
|
||||
{entities.error && <p role="alert">{entities.error.message}</p>}
|
||||
<table>
|
||||
<ListState query={entities} empty="No entities yet." />
|
||||
{!!entities.data?.length && (
|
||||
<table aria-label="Entities">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Entity</th>
|
||||
@@ -72,14 +74,15 @@ export function EntitiesTab({ client }: { client: BaoClient }) {
|
||||
<td>{e.aliases.map((a) => a.name).join(', ') || '—'}</td>
|
||||
<td>{e.policies.join(', ') || '—'}</td>
|
||||
<td>
|
||||
<button type="button" onClick={() => setAccessFor(e.name)}>
|
||||
<button type="button" aria-label={`Access ${e.name}`} onClick={() => setAccessFor(e.name)}>
|
||||
Access
|
||||
</button>{' '}
|
||||
<button type="button" onClick={() => setDraft({ name: e.name, policies: e.policies, isNew: false, entity: e })}>
|
||||
<button type="button" aria-label={`Edit ${e.name}`} onClick={() => setDraft({ name: e.name, policies: e.policies, isNew: false, entity: e })}>
|
||||
Edit
|
||||
</button>{' '}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Delete ${e.name}`}
|
||||
onClick={() => window.confirm(`Delete entity "${e.name}" and its aliases?`) && remove.mutate(e.name)}
|
||||
>
|
||||
Delete
|
||||
@@ -89,6 +92,7 @@ export function EntitiesTab({ client }: { client: BaoClient }) {
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
{remove.error && <p role="alert">{remove.error.message}</p>}
|
||||
{!draft && (
|
||||
<button type="button" onClick={() => setDraft({ name: '', policies: [], isNew: true })}>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useState, type FormEvent } from 'react'
|
||||
import type { BaoClient } from '../../api/bao'
|
||||
import { deleteGroup, listEntities, listGroups, saveGroup } from '../../api/identities'
|
||||
import { AccessEditor } from '../access/AccessEditor'
|
||||
import { ListState } from '../shared/ListState'
|
||||
import { PolicyPicker } from '../shared/PolicyPicker'
|
||||
|
||||
interface Draft {
|
||||
@@ -38,8 +39,9 @@ export function GroupsTab({ client }: { client: BaoClient }) {
|
||||
|
||||
return (
|
||||
<section>
|
||||
{groups.error && <p role="alert">{groups.error.message}</p>}
|
||||
<table>
|
||||
<ListState query={groups} empty="No groups yet." />
|
||||
{!!groups.data?.length && (
|
||||
<table aria-label="Groups">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Group</th>
|
||||
@@ -55,16 +57,17 @@ export function GroupsTab({ client }: { client: BaoClient }) {
|
||||
<td>{g.member_entity_ids.map(nameOf).join(', ') || '—'}</td>
|
||||
<td>{g.policies.join(', ') || '—'}</td>
|
||||
<td>
|
||||
<button type="button" onClick={() => setAccessFor(g.name)}>
|
||||
<button type="button" aria-label={`Access ${g.name}`} onClick={() => setAccessFor(g.name)}>
|
||||
Access
|
||||
</button>{' '}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Edit ${g.name}`}
|
||||
onClick={() => setDraft({ name: g.name, policies: g.policies, members: g.member_entity_ids, isNew: false })}
|
||||
>
|
||||
Edit
|
||||
</button>{' '}
|
||||
<button type="button" onClick={() => window.confirm(`Delete group "${g.name}"?`) && remove.mutate(g.name)}>
|
||||
<button type="button" aria-label={`Delete ${g.name}`} onClick={() => window.confirm(`Delete group "${g.name}"?`) && remove.mutate(g.name)}>
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
@@ -72,6 +75,7 @@ export function GroupsTab({ client }: { client: BaoClient }) {
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
{remove.error && <p role="alert">{remove.error.message}</p>}
|
||||
{!draft && (
|
||||
<button type="button" onClick={() => setDraft({ name: '', policies: [], members: [], isNew: true })}>
|
||||
|
||||
@@ -18,15 +18,17 @@ export function IdentitiesPage() {
|
||||
<>
|
||||
<div role="tablist" className="tabs">
|
||||
{tabs.map((t) => (
|
||||
<button key={t} type="button" role="tab" aria-selected={tab === t} onClick={() => setTab(t)}>
|
||||
<button key={t} type="button" role="tab" id={`tab-${t}`} aria-selected={tab === t} aria-controls="identities-panel" onClick={() => setTab(t)}>
|
||||
{t}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div role="tabpanel" id="identities-panel" aria-labelledby={`tab-${tab}`}>
|
||||
{tab === 'Users' && <UsersTab client={client} />}
|
||||
{tab === 'Entities' && <EntitiesTab client={client} />}
|
||||
{tab === 'Groups' && <GroupsTab client={client} />}
|
||||
{tab === 'Tokens' && <TokensTab client={client} />}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</RequireConnection>
|
||||
|
||||
@@ -72,9 +72,9 @@ test('revoke requires confirmation', async () => {
|
||||
vi.mocked(api.revokeToken).mockResolvedValue()
|
||||
const user = setup()
|
||||
const confirm = vi.spyOn(window, 'confirm').mockReturnValueOnce(false).mockReturnValueOnce(true)
|
||||
await user.click(await screen.findByRole('button', { name: 'Revoke' }))
|
||||
await user.click(await screen.findByRole('button', { name: 'Revoke token-ci' }))
|
||||
expect(api.revokeToken).not.toHaveBeenCalled()
|
||||
await user.click(screen.getByRole('button', { name: 'Revoke' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Revoke token-ci' }))
|
||||
expect(api.revokeToken).toHaveBeenCalledWith(client, 'acc-aaaaaaaa')
|
||||
confirm.mockRestore()
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useState, type FormEvent } from 'react'
|
||||
import type { BaoClient } from '../../api/bao'
|
||||
import { createToken, listTokens, revokeToken, type CreatedToken } from '../../api/tokens'
|
||||
import { useSession } from '../../api/useSession'
|
||||
import { ListState } from '../shared/ListState'
|
||||
import { PolicyPicker } from '../shared/PolicyPicker'
|
||||
|
||||
interface Draft {
|
||||
@@ -76,8 +77,9 @@ export function TokensTab({ client }: { client: BaoClient }) {
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{tokens.error && <p role="alert">{tokens.error.message}</p>}
|
||||
<table>
|
||||
<ListState query={tokens} empty="No tokens." />
|
||||
{!!tokens.data?.length && (
|
||||
<table aria-label="Tokens">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
@@ -104,6 +106,7 @@ export function TokensTab({ client }: { client: BaoClient }) {
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Revoke ${t.display_name || t.accessor}`}
|
||||
disabled={isSelf}
|
||||
title={isSelf ? 'This is the token you are signed in with' : undefined}
|
||||
onClick={() =>
|
||||
@@ -119,6 +122,7 @@ export function TokensTab({ client }: { client: BaoClient }) {
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
{revoke.error && <p role="alert">{revoke.error.message}</p>}
|
||||
{!draft && (
|
||||
<button type="button" onClick={() => setDraft(empty)}>
|
||||
|
||||
@@ -45,7 +45,7 @@ test('creates a user with selected policies', async () => {
|
||||
|
||||
test('editing keeps the username fixed and the password optional', async () => {
|
||||
const user = setup()
|
||||
await user.click(await screen.findByRole('button', { name: 'Edit' }))
|
||||
await user.click(await screen.findByRole('button', { name: 'Edit alice' }))
|
||||
expect(screen.getByLabelText('Username')).toBeDisabled()
|
||||
await user.click(await screen.findByLabelText('default'))
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
@@ -55,9 +55,9 @@ test('editing keeps the username fixed and the password optional', async () => {
|
||||
test('delete requires confirmation', async () => {
|
||||
const user = setup()
|
||||
const confirm = vi.spyOn(window, 'confirm').mockReturnValueOnce(false).mockReturnValueOnce(true)
|
||||
await user.click(await screen.findByRole('button', { name: 'Delete' }))
|
||||
await user.click(await screen.findByRole('button', { name: 'Delete alice' }))
|
||||
expect(api.deleteUser).not.toHaveBeenCalled()
|
||||
await user.click(screen.getByRole('button', { name: 'Delete' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Delete alice' }))
|
||||
expect(api.deleteUser).toHaveBeenCalledWith(client, 'alice')
|
||||
confirm.mockRestore()
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useState, type FormEvent } from 'react'
|
||||
import type { BaoClient } from '../../api/bao'
|
||||
import { deleteUser, listUsers, saveUser } from '../../api/identities'
|
||||
import { AccessEditor } from '../access/AccessEditor'
|
||||
import { ListState } from '../shared/ListState'
|
||||
import { PolicyPicker } from '../shared/PolicyPicker'
|
||||
|
||||
interface Draft {
|
||||
@@ -40,8 +41,9 @@ export function UsersTab({ client }: { client: BaoClient }) {
|
||||
|
||||
return (
|
||||
<section>
|
||||
{users.error && <p role="alert">{users.error.message}</p>}
|
||||
<table>
|
||||
<ListState query={users} empty="No users yet." />
|
||||
{!!users.data?.length && (
|
||||
<table aria-label="Users">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
@@ -55,14 +57,15 @@ export function UsersTab({ client }: { client: BaoClient }) {
|
||||
<td>{u.name}</td>
|
||||
<td>{u.policies.join(', ') || '—'}</td>
|
||||
<td>
|
||||
<button type="button" onClick={() => setAccessFor(u.name)}>
|
||||
<button type="button" aria-label={`Access ${u.name}`} onClick={() => setAccessFor(u.name)}>
|
||||
Access
|
||||
</button>{' '}
|
||||
<button type="button" onClick={() => setDraft({ ...u, password: '', ttl: u.ttl ? `${u.ttl}s` : '', isNew: false })}>
|
||||
<button type="button" aria-label={`Edit ${u.name}`} onClick={() => setDraft({ ...u, password: '', ttl: u.ttl ? `${u.ttl}s` : '', isNew: false })}>
|
||||
Edit
|
||||
</button>{' '}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Delete ${u.name}`}
|
||||
onClick={() => window.confirm(`Delete user "${u.name}"? This cannot be undone.`) && remove.mutate(u.name)}
|
||||
>
|
||||
Delete
|
||||
@@ -72,6 +75,7 @@ export function UsersTab({ client }: { client: BaoClient }) {
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
{remove.error && <p role="alert">{remove.error.message}</p>}
|
||||
{!draft && (
|
||||
<button type="button" onClick={() => setDraft(empty)}>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
interface Query {
|
||||
isPending: boolean
|
||||
error: Error | null
|
||||
data?: unknown[]
|
||||
}
|
||||
|
||||
/** Loading / error / empty feedback for a list. Renders nothing once there is data to show. */
|
||||
export function ListState({ query, empty }: { query: Query; empty: string }) {
|
||||
if (query.isPending) return <p role="status">Loading…</p>
|
||||
if (query.error) return <p role="alert">{query.error.message}</p>
|
||||
if (query.data?.length === 0) return <p>{empty}</p>
|
||||
return null
|
||||
}
|
||||
Reference in new issue
Block a user