Page MenuHomePhabricator

Make a trait for enabling temporary accounts in tests
Closed, ResolvedPublic2 Estimated Story Points

Description

UserTest has a private method for enabling temporary accounts:

private function enableAutoCreateTempUser() {
	$this->overrideConfigValue(
		MainConfigNames::AutoCreateTempUser,
		[
			'enabled' => true,
			'expireAfterDays' => null,
			'actions' => [ 'edit' ],
			'genPattern' => '*Unregistered $1',
			'matchPattern' => '*$1',
			'serialProvider' => [ 'type' => 'local' ],
			'serialMapping' => [ 'type' => 'plain-numeric' ],
		]
	);
}

code here

Setting all those defaults can get quite repetitive across tests, so it could be helpful to have a trait that does this.

Other tests that enable temporary accounts: https://codesearch.wmcloud.org/search/?q=AutoCreateTempUser&files=.*Test.php&excludeFiles=&repos=

Event Timeline

At the same time it would also be good to have a trait that disables temporary account creation. I suggest this because CheckUser has tests that fail if temporary account autocreation is enabled, because of T345578.

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

[mediawiki/core@master] [WIP] Add TempUserTestTrait

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

As part of this I've found that:

  • The RequestContext::getMain for tests seems to default to an IP address. Changing this to not do this might help fix some of the test failures when enabling temporary account autocreation.
  • There are situations where an IP actor needs to be created when temporary accounts autocreation exists for CheckUser.

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

[mediawiki/extensions/CheckUser@master] [WIP] Use TempUserTestTrait

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

Dreamy_Jazz set the point value for this task to 2.Jan 12 2024, 2:24 PM

Change 984850 merged by jenkins-bot:

[mediawiki/core@master] Add TempUserTestTrait to easily control temp user config in tests

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

Change 984861 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Use TempUserTestTrait in CheckUser tests

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

I suggest that no QA is needed for this ticket because:

  • This ticket and it's changes are about adding support for writing integration tests
  • Therefore, the code added by this ticket is never used outside of integration tests

If QA wants to take a look at the code and make recommendations, I would suggest that you inspect the code added in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/984850/. Examples of usage are in the merged patch https://gerrit.wikimedia.org/r/c/mediawiki/extensions/CheckUser/+/984861/ and the in review patch https://gerrit.wikimedia.org/r/c/mediawiki/core/+/989625.

dom_walden subscribed.

I suggest that no QA is needed for this ticket because:

This makes sense. Thanks.