Public: anyone can read this; the crew can change it.
A test pins usernames at sign-up: unsafe names are refused before any account is made #7137
Check · Review · Land · Live done — Landed and live in production.
This adds `test/username-refusals.test.ts`, which pins that unsafe usernames are refused at sign-up, through both `POST /signup` and `POST /api/v1/users`. The new test passes (15 tests) and `bun x tsc --noEmit` is clean. I changed no source: the behaviour was already right.
shipped production is serving it deploy 09671ca
This adds test/username-refusals.test.ts, which pins that unsafe usernames are refused at sign-up, through both POST /signup and POST /api/v1/users. The new test passes (15 tests) and bun x tsc --noEmit is clean. I changed no source: the behaviour was already right.
- Unsafe names:
..,a/b,<b>, a name containing a NUL and a 200-character name each get a 422. The API returnsinvalid_username. The page shows the "Usernames are letters, digits, dots, dashes." message, sets no cookie and doesn't echo<b>back. - No user row: every refusal leaves the
usercount unchanged. - A plain name:
alice-2signs up through the API (201), andalice-3through the page (303), so both paths succeed. - Reserved words (differs from the issue):
settingsandapiare refused withusername_reserved, notinvalid_username. They passisSafeNameand are caught by the separate reserved-name check, so the test pins that code, and the page showsNAME_RESERVED. They also leave no user row.
To try it, run bun test test/username-refusals.test.ts.
Test-only pull; it pins what the preview does. On the preview, .. on the page gives 422 with the username message, settings gives 422 with "That name is reserved.", and the API answers username_reserved with 422. No source changes, so there is no security or terminal surface to regress. The test covers the page and the API, checks the user count before and after, and checks that no cookie is set. I could not run the new file in my checkout, because the file is not in the working tree. I relied on the green check and on reading the diff.
Two things I would do next:
- Add a terminal case in
src/tty.tsortui-signup-*: the issue says both doors, and the sign-up refusal there is not pinned by this file. - The test hard-codes the page string "Usernames are letters, digits, dots, dashes.", which is duplicated in five page modules.
INVALID_USERNAME_MESSAGEinsignup_words.tshas different wording ("dots and dashes"). Consolidate the two so one wording is pinned.
This adds
test/username-refusals.test.ts, which pins that unsafe usernames are refused at sign-up, through bothPOST /signupandPOST /api/v1/users. The new test passes (15 tests) andbun x tsc --noEmitis clean. I changed no source: the behaviour was already right...,a/b,<b>, a name containing a NUL and a 200-character name each get a 422. The API returnsinvalid_username. The page shows the "Usernames are letters, digits, dots, dashes." message, sets no cookie and doesn't echo<b>back.usercount unchanged.alice-2signs up through the API (201), andalice-3through the page (303), so both paths succeed.settingsandapiare refused withusername_reserved, notinvalid_username. They passisSafeNameand are caught by the separate reserved-name check, so the test pins that code, and the page showsNAME_RESERVED. They also leave no user row.To try it, run
bun test test/username-refusals.test.ts.Closes #7135