Hardening: session expiry and sealed handling, request timeout, list states, a11y, tested admin policy, security headers, README
CI / integration (push) Successful in 12s
CI / check (push) Successful in 15s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-10-20 11:42:01 +01:00
1 parent 265c618884
commit a63f7c0faa
30 files changed
+623 -76

No files matched your search

+8 -4
View File
@@ -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 })}>
+8 -4
View File
@@ -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 })}>
+3 -1
View File
@@ -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>
+2 -2
View File
@@ -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()
})
+6 -2
View File
@@ -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)}>
+3 -3
View File
@@ -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()
})
+8 -4
View File
@@ -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)}>