Page MenuHomePhabricator

Handle collisions in autogenerated temporary account username provided by TempUserCreator::acquireName
Closed, ResolvedPublic3 Estimated Story PointsBUG REPORT

Assigned To
Authored By
Dreamy_Jazz
Dec 13 2023, 10:15 PM
Referenced Files
F41651670: 2024-01-05_08-09-23.png
Jan 5 2024, 5:52 PM
F41651668: 2024-01-05_08-08-25.png
Jan 5 2024, 5:52 PM
F41651666: 2024-01-05_08-07-35.png
Jan 5 2024, 5:52 PM
F41651664: 2024-01-04_14-37-12.png
Jan 5 2024, 5:52 PM
F41651661: 2024-01-04_14-36-31.png
Jan 5 2024, 5:52 PM
F41651659: 2024-01-04_14-32-18.png
Jan 5 2024, 5:52 PM
F41617626: image.png
Dec 21 2023, 11:42 PM
F41617624: image.png
Dec 21 2023, 11:42 PM

Description

As described in T349503: Update the serial mapping config for generating temporary user names on beta, the TempUserCreator::acquireName method uses SerialProvider::acquireIndex in a way that assumes it will always return an integer that has never been used before. However, the documentation for this method says the index is instead unlikely to be used again.

As discussed at T349503, this means that the TempUserCreator::create and TempUserCreator::acquireAndStashName methods must handle the situation where an index is returned that has previously been used. This code currently causes issues because this assumption means that a user can be logged in to an already existing temporary account on a collision.

Steps to replicate the issue

These steps are aimed at a local testing wiki

  1. Disable temporary account creation (if enabled)
  2. Run one of the following SQL:
    1. If using CentralAuth, run the SQL in 2A on the centralauth DB
    2. If not using CentralAuth, run the SQL in 2B on the local wiki DB
2A: SQL for step 1 when using CentralAuth
SELECT uas_value FROM global_user_autocreate_serial WHERE uas_shard = 0;
2B: SQL for step 1 when not using CentralAuth
SELECT uas_value FROM user_autocreate_serial WHERE uas_shard = 0;
  1. Keep a track of the result of the query 2A or 2B. If query 2A or 2B returned no rows, then take this number as 1.
  2. Create an account with the username that matches the temporary account format, using the number from step 3. This should usually be *Unregistered X where X is the integer from step 3, though the format will change with T349494.
  3. Log out of the new account
  4. Re-enable temporary account creation, with the serialMapping key defined with a value of [ 'type' => 'plain-numeric', 'numShards' => 1 ]
  5. Go to any page, and open the edit window.
  6. Make some changes and press save

What happens?:
The edit fails to save with the Username entered already in use error displayed:

Screenshot 2023-12-14 130214.png (1×2 px, 112 KB)

When loading any other page after this occurs, I am now logged in to that temporary account. As shown by the Special:Contributions page, this account has no contributions (so the edit did not go through):

Screenshot 2023-12-14 130254.png (1×2 px, 194 KB)

What should have happened instead?:
The edit form should display an error if after a few attempts it fails to get a temporary account username that isn't already in use.

QA Results - Local

Details

Event Timeline

Dreamy_Jazz renamed this task from Handle collisions in autogenerated temporary account username in TempUserCreator::create to Handle collisions in autogenerated temporary account username provided by TempUserCreator::acquireName.Dec 13 2023, 10:15 PM
Dreamy_Jazz claimed this task.
Dreamy_Jazz set the point value for this task to 2.

Change 982931 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/core@master] [WIP] Handle collisions from SerialProvider::acquireIndex

https://gerrit.wikimedia.org/r/982931

Change 982931 merged by jenkins-bot:

[mediawiki/core@master] Handle collisions from SerialProvider::acquireIndex

https://gerrit.wikimedia.org/r/982931

The QA of this ticket requires a local instance because it needs changes to the database/config that could cause problems if on betawikis and are not possible for patchdemo wikis.

Suggested QA steps:

  1. Enable temporary account creation using the defaults.
  2. Create three temporary accounts and note the number included in the username for the first temporary account you create
  3. Open the DB for your wiki
  4. Run the following SQL, replacing X with the number from step 2:
UPDATE user_autocreate_serial SET uas_value = X - 1;
  1. Log out of any temporary account
  2. Visit any page and open the edit window
  3. Attempt to make an edit using source mode
  4. Verify that the following error appears:

image.png (234×2 px, 37 KB)

  1. Open Special:ApiSandbox
  2. Choose edit from the action dropdown menu
  3. In the edit tab, define a page title and text content
  4. Click Make request and then Correct token and resubmit
  5. Verify the following appears:

image.png (466×2 px, 68 KB)

  1. Re-open Special:ApiSandbox
  2. Choose the acquiretempusername option from the action dropdown menu
  3. Click Make request
  4. Verify that the following appears:

image.png (466×2 px, 68 KB)

  1. Click Make request again and verify that something like the following screenshot appears. The temporary account username shown should not exist on the wiki (you can check this using Special:ListUsers):

image.png (198×2 px, 11 KB)

  1. Go back to any page and attempt to make a test edit
  2. Verify that the edit is successful and that you are logged into the temporary account with the same name as the name returned by the API in step 18

@Dreamy_Jazz Works as design as seen in the screenshots below. I will move this to Done. Thank you for your work and your QA steps as usual!

Status: ✅PASS
Environment: Local 1.42.0-alpha (15ff133)19:27, 4 January 2024
OS: macOS Sonoma 14.2
Browser: Chrome 120
Skins. Vector 2022
Device: MBA M2
Emulated Device:: n/a
Test Links:
https://en.m.wikipedia.beta.wmflabs.org/wiki/Dog#

✅AC1: https://phabricator.wikimedia.org/T353390

Verify ErrorVerify Api Page Title Error Verify acquiretempusername ErrorRequest again TUNSpecial:ListUsers Before EditSpecial:ListUsers After Edit
2024-01-04_14-32-18.png (869×3 px, 225 KB)
2024-01-04_14-36-31.png (765×3 px, 237 KB)
2024-01-04_14-37-12.png (773×3 px, 237 KB)
2024-01-05_08-07-35.png (708×3 px, 204 KB)
2024-01-05_08-08-25.png (865×3 px, 227 KB)
2024-01-05_08-09-23.png (893×3 px, 237 KB)