Repository navigation
user: keep a username unique within its group name - #99
Merged
Merged
Conversation
Login takes username@groupname, so two live users with one username in live groups of one name made it ambiguous. User create, rename, move and restore now refuse that with a conflict, as v2 did. So do group rename and restore. A user needs a group that exists. On mysql a named lock on the group name serialises the check against concurrent writers.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are blocking approval.
No open issues 🎉
What changed in this PR
This PR restores v2’s username-uniqueness rule in the MySQL and file stores, preventing ambiguous logins across live groups that share a name.
Changes:
- Check user and group creation, updates, and restoration for username conflicts; require users to reference an existing group.
- Protect MySQL uniqueness checks with group-name locks and keep group permission updates in the same transaction.
- Add conflict and concurrency tests, and seed required groups in file-store fixtures.
| File | Description |
|---|---|
routes/user.test.js |
Verify duplicate user creation and renaming return HTTP 409. |
lib/user/test/mysql.js |
Test concurrent user creation and group-renaming conflicts. |
lib/user/test/index.js |
Cover uniqueness, missing groups, moves, and restoration. |
lib/user/store/mysql.js |
Add transactional username checks, group-name locks, and group validation. |
lib/user/store/file.js |
Validate username availability and group existence during user writes. |
lib/user/store/base.js |
Add shared conflict errors and file-store uniqueness helpers. |
lib/store/file.test.js |
Seed groups required by user fixtures. |
lib/group/store/mysql.js |
Check group-name transitions and update permissions transactionally. |
lib/group/store/file.js |
Check group creation, renaming, and restoration for username conflicts. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two
POST /usercalls with the same username andgidboth answer 201. APUTcan also rename a user onto a name its group already has. Login takesusername@groupname, and with two matching rows it signs in whichever one the password fits. That name no longer identifies one user.v2 refused this in
User/Sanity.pm_username_exists. A username had to be unique among live users in every live group with that group's name. This PR applies the same rule in the mysql and file stores. User create, rename, move and restore check it. So do group rename, restore, and create with an explicit id, since a destroyed group leaves its users behind. A clash answers 409 withusername <name>@<group> is not unique.A user now needs a group that exists, or the store answers 400. Without that, two users could share a login in a gid that a later group takes.
On mysql each check runs in a transaction under a
GET_LOCKon the group name, as zone names already do. The lock key drops trailing spaces because mysql compares names that way. A new test starts four creates of one login at once and expects one winner. Without the lock, two of them won. The group'susable_nsis now written inside the same transaction, so a refused rename leaves it alone. A restore throughdelete({ deleted: false })goes throughputand is checked too.The file store tests in
lib/store/file.test.jsnow seed group 1 before creating users in it.v2's t/06_users.t checks this at lines 236 and 306. With this change v3 refuses both. The later failures at 395 and 408 go away.