Page MenuHomePhabricator

Ensure api-testing MediaWiki core tests pass when temp account feature flag is enabled
Closed, ResolvedPublic

Description

Acceptance criteria:

Status (22 May 2024):

119:32:21 1) Page History
219:32:21 "before all" hook in "Page History":
319:32:21 AssertionError: User "127.0.0.1": Action "edit" returned error code "badtoken": Invalid CSRF token.!
419:32:21 at Client.action (node_modules/api-testing/lib/actionapi.js:123:11)
519:32:21 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
619:32:21 at async Client.edit (node_modules/api-testing/lib/actionapi.js:322:18)
719:32:21 at async Context.<anonymous> (tests/api-testing/REST/PageHistory.js:60:16)
819:32:21
919:32:21 2) Testing default autopatrolling rights
1019:32:21 should confirm autopatrolling rights:
1119:32:21
1219:32:21 AssertionError: expected [ { type: 'edit', …(3) }, …(1) ] to have the same members as [ …(2) ]
1319:32:21 + expected - actual
1419:32:21
1519:32:21 [
1619:32:21 {
1719:32:21 - "temp": ""
1819:32:21 + "anon": ""
1919:32:21 "type": "edit"
2019:32:21 "unpatrolled": ""
2119:32:21 "user": "~2024-4"
2219:32:21 }
2319:32:21
2419:32:21 at Context.<anonymous> (tests/api-testing/action/Autopatrolling.js:27:10)
2519:32:21 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2619:32:21
2719:32:21 3) The edit action
2819:32:21 allows a page to be created and modified by an anonymous user:
2919:32:21
3019:32:21 AssertionError: expected '~2024-5' to equal '127.0.0.1'
3119:32:21 + expected - actual
3219:32:21
3319:32:21 -~2024-5
3419:32:21 +127.0.0.1
3519:32:21
3619:32:21 at testEditAndLog (tests/api-testing/action/Edit.js:25:10)
3719:32:21 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
3819:32:21 at async Context.<anonymous> (tests/api-testing/action/Edit.js:54:3)
3919:32:21
4019:32:21 4) Page protection
4119:32:21 levels
4219:32:21 should NOT allow anonymous user to edit Protected page:
4319:32:21
4419:32:21 AssertionError: expected 'badtoken' to equal 'protectedpage'
4519:32:21 + expected - actual
4619:32:21
4719:32:21 -badtoken
4819:32:21 +protectedpage
4919:32:21
5019:32:21 at Context.<anonymous> (tests/api-testing/action/PageProtection.js:165:11)
5119:32:21 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
5219:32:21
5319:32:21 5) Page protection
5419:32:21 levels
5519:32:21 should NOT allow anonymous user to edit Semi Protected page:
5619:32:21
5719:32:21 AssertionError: expected 'badtoken' to equal 'protectedpage'
5819:32:21 + expected - actual
5919:32:21
6019:32:21 -badtoken
6119:32:21 +protectedpage
6219:32:21
6319:32:21 at Context.<anonymous> (tests/api-testing/action/PageProtection.js:176:11)
6419:32:21 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
6519:32:21
6619:32:21 6) Page protection
6719:32:21 levels
6819:32:21 should allow a restriction to be specified that allows users to edit it and only sysops to move a page:
6919:32:21
7019:32:21 AssertionError: expected 'badtoken' to equal 'protectedpage'
7119:32:21 + expected - actual
7219:32:21
7319:32:21 -badtoken
7419:32:21 +protectedpage
7519:32:21
7619:32:21 at Context.<anonymous> (tests/api-testing/action/PageProtection.js:206:11)
7719:32:21 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

The work here is a mix of:

  1. If using an anonymous user and anonymous token, only make one edit per test. That's because subsequent edits would be done as a temp user. (Alternatively, clear the cached token and re-request it.)
  2. If we are not explicitly testing anonymous editing behavior, consider just using a regular, named user account for the edits
  3. In some cases, business logic needs to be updated. For example, PageHistoryCountHandler should not include temp account contributions in the getAnonAccount method, to be consistent with other APIs - T365673: PageHistoryCountHandler should be able to show edit counts from temporary accounts.

Business logic changes (like T365673) should be tracked in subtasks. Patches that update core's api-testing tests can tag this task.

Event Timeline

kostajh updated the task description. (Show Details)

Change #1035317 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[mediawiki/core@master] api-testing: Reset REST client before each test run

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

kostajh renamed this task from Ensure api-testing tests pass when temp account feature flag is enabled to Ensure api-testing MediaWiki core tests pass when temp account feature flag is enabled.May 23 2024, 8:29 AM

While we work on adapting the tests to work with temp accounts, two things we could consider:

  • create a hack to disable temp accounts via a LocalSettings override, so api-testing tests always run with temp accounts being disabled
  • selectively skip failing api-testing tests if temp accounts are enabled (by querying siteinfo)

Change #1053275 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[mediawiki/core@master] api-testing/REST/Page.js: Use authenticated user for edits

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

Change #1053284 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[mediawiki/core@master] api-testing/REST/Update.js: Use named user for edits

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

Change #1035317 merged by jenkins-bot:

[mediawiki/core@master] api-testing/REST/Creation.js: Reset REST client before each test run

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

Mimurawil changed the task status from Open to In Progress.Jul 10 2024, 3:32 PM
Mimurawil claimed this task.

Change #1053362 had a related patch set uploaded (by Mimurawil; author: Mimurawil):

[mediawiki/core@master] api-testing/action/Edit.js: Adjust username assertion for anonymous

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

Change #1053368 had a related patch set uploaded (by Mimurawil; author: Mimurawil):

[mediawiki/core@master] api-testing/action/Autopatrolling.js: adjust key prop for temp account

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

Change #1053380 had a related patch set uploaded (by Mimurawil; author: Mimurawil):

[mediawiki/core@master] api-testing/REST/PageHistory.js: update tests for temp account

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

Change #1053382 had a related patch set uploaded (by Mimurawil; author: Mimurawil):

[mediawiki/core@master] api-testing/action/PageProtection.js: clear state for each test

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

Change #1053275 merged by jenkins-bot:

[mediawiki/core@master] api-testing/REST/Page.js: Use authenticated user for edits

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

Change #1053284 merged by jenkins-bot:

[mediawiki/core@master] api-testing/REST/Update.js: Use named user for edits

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

Change #1053362 merged by jenkins-bot:

[mediawiki/core@master] api-testing/action/Edit.js: Adjust username assertion for anonymous

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

Change #1053368 merged by jenkins-bot:

[mediawiki/core@master] api-testing/action/Autopatrolling.js: adjust key prop for temp account

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

Change #1053380 merged by jenkins-bot:

[mediawiki/core@master] api-testing/REST/PageHistory.js: update tests for temp account

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

Change #1053382 merged by jenkins-bot:

[mediawiki/core@master] api-testing/action/PageProtection.js: clear state for each test

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

Can this be closed, now that https://gerrit.wikimedia.org/r/c/mediawiki/core/+/980947 was merged? (It's not the patch in the task description.)

Dreamy_Jazz updated the task description. (Show Details)
Dreamy_Jazz updated the task description. (Show Details)

Going to mark this as resolved, given that both patches (the one linked and the one that was merged) are passing their tests.