wiki.techinc.nl/tests/phpunit/integration/includes/user/TempUser/RealTempUserConfigTest.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

285 lines
7.8 KiB
PHP
Raw Normal View History

<?php
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
namespace MediaWiki\Tests\Integration\User\TempUser;
use MediaWiki\Permissions\SimpleAuthority;
use MediaWiki\Tests\MockDatabase;
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
use MediaWiki\Tests\User\TempUser\TempUserTestTrait;
use MediaWiki\User\TempUser\Pattern;
use MediaWiki\User\UserIdentityValue;
use Wikimedia\Rdbms\IExpression;
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
use Wikimedia\TestingAccessWrapper;
use Wikimedia\Timestamp\ConvertibleTimestamp;
/**
* @covers \MediaWiki\User\TempUser\RealTempUserConfig
* @group Database
*/
class RealTempUserConfigTest extends \MediaWikiIntegrationTestCase {
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
use TempUserTestTrait;
public static function provideIsAutoCreateAction() {
return [
'disabled' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => false,
'configOverrides' => [],
'action' => 'edit',
'expected' => false
],
'disabled by action' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'configOverrides' => [ 'actions' => [] ],
'action' => 'edit',
'expected' => false
],
'enabled' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'configOverrides' => [],
'action' => 'edit',
'expected' => true
],
// Create isn't an action in the ActionFactory sense, but is is an
// action in PermissionManager
'create' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'configOverrides' => [],
'action' => 'create',
'expected' => true
],
'unknown action' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'configOverrides' => [],
'action' => 'foo',
'expected' => false
],
];
}
/**
* @dataProvider provideIsAutoCreateAction
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
* @param bool $enabled
* @param array $configOverrides
* @param string $action
* @param bool $expected
*/
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
public function testIsAutoCreateAction( $enabled, $configOverrides, $action, $expected ) {
if ( $enabled ) {
$this->enableAutoCreateTempUser( $configOverrides );
} else {
$this->disableAutoCreateTempUser( $configOverrides );
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
}
$tuc = $this->getServiceContainer()->getTempUserConfig();
$this->assertSame( $expected, $tuc->isAutoCreateAction( $action ) );
}
public static function provideShouldAutoCreate() {
return [
'enabled' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'id' => 0,
'rights' => [ 'createaccount' ],
'action' => 'edit',
'expected' => true
],
'disabled by config' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => false,
'id' => 0,
'rights' => [ 'createaccount' ],
'action' => 'edit',
'expected' => false
],
'logged in' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'id' => 1,
'rights' => [ 'createaccount' ],
'action' => 'edit',
'expected' => false
],
'no createaccount right' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'id' => 0,
'rights' => [ 'edit' ],
'action' => 'edit',
'expected' => false
],
'wrong action' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'id' => 0,
'rights' => [ 'createaccount' ],
'action' => 'upload',
'expected' => false
],
];
}
/**
* @dataProvider provideShouldAutoCreate
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
* @param bool $enabled
* @param int $id
* @param string[] $rights
* @param string $action
* @param bool $expected
*/
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
public function testShouldAutoCreate( $enabled, $id, $rights, $action, $expected ) {
if ( $enabled ) {
$this->enableAutoCreateTempUser();
} else {
$this->disableAutoCreateTempUser();
}
$tuc = $this->getServiceContainer()->getTempUserConfig();
$user = new SimpleAuthority(
new UserIdentityValue( $id, $id ? 'Test' : '127.0.0.1' ),
$rights
);
$this->assertSame( $expected, $tuc->shouldAutoCreate( $user, $action ) );
}
public static function provideIsTempName() {
return [
'disabled' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => false,
'name' => '~Some user',
'expected' => false,
],
'default mismatch' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'name' => 'Test',
'expected' => false,
],
'default match' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'name' => '~Some user',
'expected' => true,
],
];
}
/**
* @dataProvider provideIsTempName
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
* @param bool $enabled
* @param string $name
* @param bool $expected
*/
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
public function testIsTempName( $enabled, $name, $expected ) {
if ( $enabled ) {
$this->enableAutoCreateTempUser();
} else {
$this->disableAutoCreateTempUser();
}
$tuc = $this->getServiceContainer()->getTempUserConfig();
$this->assertSame( $expected, $tuc->isTempName( $name ) );
}
/** @dataProvider provideGetPlaceholderName */
public function testGetPlaceholderName( $useYear, $expected ) {
$this->enableAutoCreateTempUser( [ 'serialProvider' => [ 'type' => 'local', 'useYear' => $useYear ] ] );
ConvertibleTimestamp::setFakeTime( '20210101000000' );
$this->assertSame( $expected, $this->getServiceContainer()->getTempUserConfig()->getPlaceholderName() );
}
public static function provideGetPlaceholderName() {
return [
'no year' => [ false, '~*' ],
'with year' => [ true, '~2021-*' ],
];
}
public static function provideIsReservedName() {
return [
'no matchPattern when disabled' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => false,
'configOverrides' => [ 'reservedPattern' => null ],
'name' => '~39',
'expected' => false,
],
'matchPattern match' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'configOverrides' => [],
'name' => '~39',
'expected' => true,
],
'genPattern match' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => true,
'configOverrides' => [ 'matchPattern' => null ],
'name' => '~39',
'expected' => true,
],
'reservedPattern match with enabled=false' => [
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
'enabled' => false,
'configOverrides' => [ 'reservedPattern' => '~$1' ],
'name' => '~Foo*',
'expected' => true
]
];
}
/**
* @dataProvider provideIsReservedName
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
* @param bool $enabled
* @param array $configOverrides
* @param string $name
* @param bool $expected
*/
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
public function testIsReservedName( $enabled, $configOverrides, $name, $expected ) {
if ( $enabled ) {
$this->enableAutoCreateTempUser( $configOverrides );
} else {
$this->disableAutoCreateTempUser( $configOverrides );
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
}
$tuc = $this->getServiceContainer()->getTempUserConfig();
$this->assertSame( $expected, $tuc->isReservedName( $name ) );
}
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
public function testGetMatchPatterns() {
$this->enableAutoCreateTempUser( [ 'matchPattern' => [ '*$1', '~$1' ] ] );
$tuc = $this->getServiceContainer()->getTempUserConfig();
$this->assertCount( 2, $tuc->getMatchPatterns() );
$actualPatterns = array_map( static function ( Pattern $pattern ) {
return TestingAccessWrapper::newFromObject( $pattern )->pattern;
}, $tuc->getMatchPatterns() );
$this->assertArrayEquals( [ '*$1', '~$1' ], $actualPatterns );
}
public function testGetMatchPattern() {
$this->hideDeprecated( 'MediaWiki\User\TempUser\RealTempUserConfig::getMatchPattern' );
Support multiple matchPatterns in temp user autocreate config Why: * There is a need to update the generation and match pattern on WMF wikis to a new format that includes the year and starts with `~`. As such, the 'matchPattern' key needs to be updated. * Removing the old 'matchPattern' from the wgAutoCreateTempUser config currently leaves existing temporary accounts as no longer recongnised as temporary accounts. * Instead, the 'matchPattern' needs to be able to take an array of string patterns so that old patterns can still be used for matching. What: * Update the MainConfigSchama to indicate that 'matchPattern' in the wgAutoCreateTempUser config can be an array of strings. * Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig:: getMatchPattern. This is needed because ::getMatchPattern was typed to only ever return one Pattern, which is no longer the case with this config change. * Update the RealTempUserConfig to support multiple patterns defined in the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method returns the pattern or first pattern if multiple are defined to allow time for existing usages of this deprecated method to be updated. * Update the RealTempUserConfig to rely on other methods instead of checking object property values where possible (e.g. use ::isEnabled instead of checking $this->enabled) to allow easier unit testing. * Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig ::getMatchPatterns instead of ::getMatchPattern. * Update mediawiki.util/util.js to be able to parse the 'matchPattern' value when it is an array of strings. * Update maintenance/userOptions.php to use ::getMatchPatterns instead of ::getMatchPattern. * Add and update unit and integration tests for the new code, as well as expanding coverage over existing code that was indirectly affected. Bug: T354619 Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-10 23:40:27 +00:00
$this->enableAutoCreateTempUser( [ 'matchPattern' => [ '*$1', '~$1' ] ] );
$tuc = $this->getServiceContainer()->getTempUserConfig();
$this->assertSame( '*$1', TestingAccessWrapper::newFromObject( $tuc->getMatchPattern() )->pattern );
}
public function testGetMatchCondition() {
$db = new MockDatabase;
$this->enableAutoCreateTempUser( [ 'matchPattern' => [ '*$1', '~$1' ] ] );
$tuc = $this->getServiceContainer()->getTempUserConfig();
$this->assertEquals(
"(foo LIKE '*%' ESCAPE '`' OR foo LIKE '~%' ESCAPE '`')",
$tuc->getMatchCondition( $db, 'foo', IExpression::LIKE )->toSql( $db ),
'LIKE allows any of the patterns'
);
$this->assertEquals(
"(foo NOT LIKE '*%' ESCAPE '`' AND foo NOT LIKE '~%' ESCAPE '`')",
$tuc->getMatchCondition( $db, 'foo', IExpression::NOT_LIKE )->toSql( $db ),
'NOT LIKE disallows all of the patterns'
);
$this->enableAutoCreateTempUser( [ 'matchPattern' => [ '*$1' ] ] );
$tuc = $this->getServiceContainer()->getTempUserConfig();
$this->assertEquals(
"foo LIKE '*%' ESCAPE '`'",
$tuc->getMatchCondition( $db, 'foo', IExpression::LIKE )->toSql( $db ),
'With a single pattern, parentheses are omitted'
);
$this->assertEquals(
"foo NOT LIKE '*%' ESCAPE '`'",
$tuc->getMatchCondition( $db, 'foo', IExpression::NOT_LIKE )->toSql( $db ),
'With a single pattern, parentheses are omitted'
);
}
}