From a39c0f77196e6dd1917646d91a2d710a44e182cd Mon Sep 17 00:00:00 2001 From: tgiachi Date: Thu, 12 Nov 2026 14:59:37 +0100 Subject: [PATCH] fix(web): clear the short-password complaint when the password is changed Found in a real browser: after the complaint, typing a valid password left it on screen until the next submit. Same in the reset dialog and the add form. --- web/src/pages/admin/AddUserForm.test.tsx | 11 +++++++++++ web/src/pages/admin/AddUserForm.tsx | 5 ++++- web/src/pages/admin/UserList.test.tsx | 12 ++++++++++++ web/src/pages/admin/UserList.tsx | 7 ++++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/web/src/pages/admin/AddUserForm.test.tsx b/web/src/pages/admin/AddUserForm.test.tsx index 689ca1c..28e1ff6 100644 --- a/web/src/pages/admin/AddUserForm.test.tsx +++ b/web/src/pages/admin/AddUserForm.test.tsx @@ -57,6 +57,17 @@ test('a password of seven characters is refused here, with no request', async () expect(calls).toHaveLength(0) }) +test('the complaint about a short password goes away as soon as the password is changed', async () => { + mockFetch({}) + renderForm() + await userEvent.type(email(), 'new@example.org') + await userEvent.type(password(), '1234567') + await userEvent.click(add()) + expect(await screen.findByRole('alert')).toBeInTheDocument() + await userEvent.type(password(), '8') + expect(screen.queryByRole('alert')).not.toBeInTheDocument() +}) + test('adding sends the trimmed email, the password and the role, then empties the form', async () => { const { calls } = mockFetch({ 'POST /api/v1/users': created }) renderForm() diff --git a/web/src/pages/admin/AddUserForm.tsx b/web/src/pages/admin/AddUserForm.tsx index 9cc981c..623ce86 100644 --- a/web/src/pages/admin/AddUserForm.tsx +++ b/web/src/pages/admin/AddUserForm.tsx @@ -67,7 +67,10 @@ export default function AddUserForm() { type="password" value={password} autoComplete="new-password" - onChange={(e) => setPassword(e.target.value)} + onChange={(e) => { + setPassword(e.target.value) + setTooShort(false) + }} />

{t('admin.users.passwordHint')}

diff --git a/web/src/pages/admin/UserList.test.tsx b/web/src/pages/admin/UserList.test.tsx index 64039c7..727541c 100644 --- a/web/src/pages/admin/UserList.test.tsx +++ b/web/src/pages/admin/UserList.test.tsx @@ -107,6 +107,18 @@ test('resetting a password asks for the new one, and a short one is refused with expect(calledWith(calls, 'PUT /api/v1/users/2/password')).toHaveLength(0) }) +test('the complaint about a short password goes away as soon as the password is changed', async () => { + mockFetch(routes({ 'PUT /api/v1/users/2/password': none })) + renderList() + await userEvent.click(within(await row('ann@example.org')).getByRole('button', { name: 'Reset password for ann@example.org' })) + const dialog = await screen.findByRole('dialog') + await userEvent.type(within(dialog).getByLabelText('New password'), '1234567') + await userEvent.click(within(dialog).getByRole('button', { name: 'Reset password' })) + expect(await within(dialog).findByRole('alert')).toBeInTheDocument() + await userEvent.type(within(dialog).getByLabelText('New password'), '8') + expect(within(dialog).queryByRole('alert')).not.toBeInTheDocument() +}) + test('a password longer than 256 bytes is refused without a request', async () => { const { calls } = mockFetch(routes({ 'PUT /api/v1/users/2/password': none })) renderList() diff --git a/web/src/pages/admin/UserList.tsx b/web/src/pages/admin/UserList.tsx index 1d4d08a..a3479d5 100644 --- a/web/src/pages/admin/UserList.tsx +++ b/web/src/pages/admin/UserList.tsx @@ -84,7 +84,12 @@ function ResetDialog({ user, onClose, onDone }: { user: User; onClose: () => voi
- setPassword(e.target.value)} /> + { + setPassword(e.target.value) + setTooShort(false) + }} + />

{t('admin.users.passwordHint')}

{tooShort && (