Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
2022-08-17 20:33:06 +00:00
|
|
|
|
use MediaWiki\MainConfigNames;
|
2021-05-03 20:38:48 +00:00
|
|
|
|
use MediaWiki\Tests\Unit\DummyServicesTrait;
|
2022-03-16 04:08:00 +00:00
|
|
|
|
use MediaWiki\User\UserRigorOptions;
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
use Psr\Log\LogLevel;
|
2020-03-31 23:29:51 +00:00
|
|
|
|
use Wikimedia\Message\ITextFormatter;
|
|
|
|
|
|
use Wikimedia\Message\MessageValue;
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
|
2020-04-11 08:10:18 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers MediaWiki\User\UserNameUtils
|
|
|
|
|
|
* @author DannyS712
|
|
|
|
|
|
*/
|
2021-07-20 07:29:47 +00:00
|
|
|
|
class UserNameUtilsTest extends MediaWikiUnitTestCase {
|
2021-05-03 20:38:48 +00:00
|
|
|
|
use DummyServicesTrait;
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideIsValid
|
|
|
|
|
|
* @covers MediaWiki\User\UserNameUtils::isValid
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIsValid( string $name, bool $result ) {
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
|
$result,
|
2021-07-27 11:41:13 +00:00
|
|
|
|
$this->getDummyUserNameUtils()->isValid( $name )
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function provideIsValid() {
|
|
|
|
|
|
return [
|
|
|
|
|
|
'Empty string' => [ '', false ],
|
|
|
|
|
|
'Blank space' => [ ' ', false ],
|
|
|
|
|
|
'Starts with small letter' => [ 'abcd', false ],
|
|
|
|
|
|
'Contains slash' => [ 'Ab/cd', false ],
|
|
|
|
|
|
'Whitespace' => [ 'Ab cd', true ],
|
|
|
|
|
|
'IP' => [ '192.168.1.1', false ],
|
|
|
|
|
|
'IP range' => [ '116.17.184.5/32', false ],
|
|
|
|
|
|
'IPv6 range' => [ '::e:f:2001/96', false ],
|
|
|
|
|
|
'Reserved Namespace' => [ 'User:Abcd', false ],
|
|
|
|
|
|
'Starts with Numbers' => [ '12abcd232', true ],
|
|
|
|
|
|
'Start with ? mark' => [ '?abcd', true ],
|
|
|
|
|
|
'Start with #' => [ '#abcd', false ],
|
|
|
|
|
|
' Mixed scripts' => [ 'Abcdകഖഗഘ', true ],
|
|
|
|
|
|
'ZWNJ- Format control character' => [ 'ജോസ്തോമസ്', false ],
|
|
|
|
|
|
' Ideographic space' => [ 'Ab cd', false ],
|
|
|
|
|
|
'Looks too much like an IPv4 address (1)' => [ '300.300.300.300', false ],
|
|
|
|
|
|
'Looks too much like an IPv4 address (2)' => [ '302.113.311.900', false ],
|
|
|
|
|
|
'Reserved for usage by UseMod for cloaked logged-out users' => [ '203.0.113.xxx', false ],
|
2021-03-19 18:36:44 +00:00
|
|
|
|
'Disallowed characters' => [ "\u{E000}", false ],
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideIsUsable
|
|
|
|
|
|
* @covers MediaWiki\User\UserNameUtils::isUsable
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIsUsable( string $name, bool $result ) {
|
2020-03-31 23:29:51 +00:00
|
|
|
|
$textFormatter = $this->getMockForAbstractClass( ITextFormatter::class );
|
|
|
|
|
|
$textFormatter->method( 'format' )
|
2021-04-22 07:56:11 +00:00
|
|
|
|
->with( MessageValue::new( 'reserved-user' ) )
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
->willReturn( 'reserved-user' );
|
|
|
|
|
|
|
2021-07-27 11:41:13 +00:00
|
|
|
|
$utils = $this->getDummyUserNameUtils( [
|
2022-08-17 20:33:06 +00:00
|
|
|
|
MainConfigNames::ReservedUsernames => [
|
2021-07-27 11:41:13 +00:00
|
|
|
|
'MediaWiki default',
|
|
|
|
|
|
'msg:reserved-user'
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
],
|
2021-07-27 11:41:13 +00:00
|
|
|
|
'textFormatter' => $textFormatter,
|
|
|
|
|
|
] );
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
$this->assertSame(
|
|
|
|
|
|
$result,
|
|
|
|
|
|
$utils->isUsable( $name )
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function provideIsUsable() {
|
|
|
|
|
|
return [
|
|
|
|
|
|
'Only valid user names are creatable' => [ '', false ],
|
|
|
|
|
|
'Reserved names cannot be used' => [ 'MediaWiki default', false ],
|
|
|
|
|
|
'Names can also be reserved via msg: ' => [ 'reserved-user', false ],
|
|
|
|
|
|
'User names with no issues can be used' => [ 'FooBar', true ],
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers MediaWiki\User\UserNameUtils::isCreatable
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIsCreatable() {
|
2021-02-07 13:10:36 +00:00
|
|
|
|
$logger = new TestLogger( true, static function ( $message ) {
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
$message = str_replace(
|
|
|
|
|
|
'MediaWiki\\User\\UserNameUtils::isCreatable: ',
|
|
|
|
|
|
'',
|
|
|
|
|
|
$message
|
|
|
|
|
|
);
|
|
|
|
|
|
return $message;
|
|
|
|
|
|
} );
|
2021-07-27 11:41:13 +00:00
|
|
|
|
$utils = $this->getDummyUserNameUtils( [
|
|
|
|
|
|
'logger' => $logger,
|
|
|
|
|
|
] );
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
|
|
|
|
|
|
$longUserName = str_repeat( 'q', 1000 );
|
|
|
|
|
|
$this->assertFalse(
|
|
|
|
|
|
$utils->isCreatable( $longUserName ),
|
|
|
|
|
|
'longUserName is too long'
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->assertSame( [
|
|
|
|
|
|
[ LogLevel::DEBUG, "'$longUserName' uncreatable due to length" ],
|
|
|
|
|
|
], $logger->getBuffer() );
|
|
|
|
|
|
$logger->clearBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
$atUserName = 'Foo@Bar';
|
|
|
|
|
|
$this->assertFalse(
|
|
|
|
|
|
$utils->isCreatable( $atUserName ),
|
|
|
|
|
|
'User name contains invalid character'
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->assertSame( [
|
|
|
|
|
|
[ LogLevel::DEBUG, "'$atUserName' uncreatable due to wgInvalidUsernameCharacters" ],
|
|
|
|
|
|
], $logger->getBuffer() );
|
|
|
|
|
|
$logger->clearBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
|
$utils->isCreatable( 'FooBar' ),
|
|
|
|
|
|
'User names with no issues can be created'
|
|
|
|
|
|
);
|
2022-02-28 03:05:58 +00:00
|
|
|
|
|
|
|
|
|
|
$tempUserName = '*Unregistered 1234';
|
|
|
|
|
|
$this->assertFalse(
|
|
|
|
|
|
$utils->isCreatable( $tempUserName ),
|
|
|
|
|
|
'UI account creation with the temp user prefix needs to be prevented'
|
|
|
|
|
|
);
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideGetCanonical
|
|
|
|
|
|
* @covers MediaWiki\User\UserNameUtils::getCanonical
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testGetCanonical( string $name, array $expectedArray ) {
|
2021-07-27 11:41:13 +00:00
|
|
|
|
$utils = $this->getDummyUserNameUtils();
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
foreach ( $expectedArray as $validate => $expected ) {
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
|
$expected,
|
|
|
|
|
|
$utils->getCanonical( $name, $validate ),
|
|
|
|
|
|
"Validating '$name' with level '$validate' should be '$expected'"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function provideGetCanonical() {
|
|
|
|
|
|
return [
|
|
|
|
|
|
'Normal name' => [
|
|
|
|
|
|
'Normal name',
|
|
|
|
|
|
[
|
2022-03-16 04:08:00 +00:00
|
|
|
|
UserRigorOptions::RIGOR_CREATABLE => 'Normal name',
|
|
|
|
|
|
UserRigorOptions::RIGOR_USABLE => 'Normal name',
|
|
|
|
|
|
UserRigorOptions::RIGOR_VALID => 'Normal name',
|
|
|
|
|
|
UserRigorOptions::RIGOR_NONE => 'Normal name'
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
]
|
|
|
|
|
|
],
|
|
|
|
|
|
'Leading space' => [
|
|
|
|
|
|
' Leading space',
|
2022-03-16 04:08:00 +00:00
|
|
|
|
[ UserRigorOptions::RIGOR_CREATABLE => 'Leading space' ]
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
],
|
|
|
|
|
|
'Trailing space' => [
|
|
|
|
|
|
'Trailing space ',
|
2022-03-16 04:08:00 +00:00
|
|
|
|
[ UserRigorOptions::RIGOR_CREATABLE => 'Trailing space' ]
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
],
|
2022-02-18 18:57:37 +00:00
|
|
|
|
'Subject namespace prefix' => [
|
|
|
|
|
|
'User:Username',
|
|
|
|
|
|
[
|
2022-03-16 04:08:00 +00:00
|
|
|
|
UserRigorOptions::RIGOR_NONE => 'Username'
|
2022-02-18 18:57:37 +00:00
|
|
|
|
]
|
|
|
|
|
|
],
|
|
|
|
|
|
'Talk namespace prefix' => [
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
'Talk:Username',
|
|
|
|
|
|
[
|
2022-03-16 04:08:00 +00:00
|
|
|
|
UserRigorOptions::RIGOR_CREATABLE => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_USABLE => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_VALID => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_NONE => 'Talk:Username'
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
]
|
|
|
|
|
|
],
|
|
|
|
|
|
'With hash' => [
|
|
|
|
|
|
'name with # hash',
|
|
|
|
|
|
[
|
2022-03-16 04:08:00 +00:00
|
|
|
|
UserRigorOptions::RIGOR_CREATABLE => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_USABLE => false
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
]
|
|
|
|
|
|
],
|
|
|
|
|
|
'Multi spaces' => [
|
|
|
|
|
|
'Multi spaces',
|
|
|
|
|
|
[
|
2022-03-16 04:08:00 +00:00
|
|
|
|
UserRigorOptions::RIGOR_CREATABLE => 'Multi spaces',
|
|
|
|
|
|
UserRigorOptions::RIGOR_USABLE => 'Multi spaces'
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
]
|
|
|
|
|
|
],
|
|
|
|
|
|
'Lowercase' => [
|
|
|
|
|
|
'lowercase',
|
2022-03-16 04:08:00 +00:00
|
|
|
|
[ UserRigorOptions::RIGOR_CREATABLE => 'Lowercase' ]
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
],
|
|
|
|
|
|
'Invalid character' => [
|
|
|
|
|
|
'in[]valid',
|
|
|
|
|
|
[
|
2022-03-16 04:08:00 +00:00
|
|
|
|
UserRigorOptions::RIGOR_CREATABLE => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_USABLE => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_VALID => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_NONE => 'In[]valid'
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
]
|
|
|
|
|
|
],
|
|
|
|
|
|
'With slash' => [
|
|
|
|
|
|
'with / slash',
|
|
|
|
|
|
[
|
2022-03-16 04:08:00 +00:00
|
|
|
|
UserRigorOptions::RIGOR_CREATABLE => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_USABLE => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_VALID => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_NONE => 'With / slash'
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
]
|
|
|
|
|
|
],
|
2021-07-28 21:17:53 +00:00
|
|
|
|
// 'interwiki' is a valid interwiki prefix, per configuration of the
|
|
|
|
|
|
// title formatter in DummyServicesTrait::getDummyUserNameUtils()
|
|
|
|
|
|
'Interwiki prefix in username' => [
|
|
|
|
|
|
'interwiki:Username',
|
|
|
|
|
|
[
|
2022-03-16 04:08:00 +00:00
|
|
|
|
UserRigorOptions::RIGOR_CREATABLE => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_USABLE => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_VALID => false,
|
|
|
|
|
|
UserRigorOptions::RIGOR_NONE => 'Interwiki:Username'
|
2021-07-28 21:17:53 +00:00
|
|
|
|
]
|
|
|
|
|
|
],
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers MediaWiki\User\UserNameUtils::getCanonical
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testGetCanonical_bad() {
|
|
|
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
|
|
|
|
$this->expectExceptionMessage( 'Invalid parameter value for validation' );
|
2021-07-27 11:41:13 +00:00
|
|
|
|
$this->getDummyUserNameUtils()->getCanonical( 'ValidName', 'InvalidValidationValue' );
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideIPs
|
|
|
|
|
|
* @covers MediaWiki\User\UserNameUtils::isIP
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIsIP( string $value, bool $result ) {
|
2021-07-27 11:41:13 +00:00
|
|
|
|
$utils = $this->getDummyUserNameUtils();
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
$this->assertSame(
|
|
|
|
|
|
$result,
|
|
|
|
|
|
$utils->isIP( $value )
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function provideIPs() {
|
|
|
|
|
|
return [
|
|
|
|
|
|
'Empty string' => [ '', false ],
|
|
|
|
|
|
'Blank space' => [ ' ', false ],
|
|
|
|
|
|
'IPv4 private 10/8 (1)' => [ '10.0.0.0', true ],
|
|
|
|
|
|
'IPv4 private 10/8 (2)' => [ '10.255.255.255', true ],
|
|
|
|
|
|
'IPv4 private 192.168/16' => [ '192.168.1.1', true ],
|
|
|
|
|
|
'IPv4 example' => [ '203.0.113.0', true ],
|
|
|
|
|
|
'IPv6 example' => [ '2002:ffff:ffff:ffff:ffff:ffff:ffff:ffff', true ],
|
|
|
|
|
|
// Not valid IPs but classified as such by MediaWiki for negated asserting
|
|
|
|
|
|
// of whether this might be the identifier of a logged-out user or whether
|
|
|
|
|
|
// to allow usernames like it.
|
|
|
|
|
|
'Looks too much like an IPv4 address' => [ '300.300.300.300', true ],
|
|
|
|
|
|
'Assigned by UseMod to cloaked logged-out users' => [ '203.0.113.xxx', true ],
|
|
|
|
|
|
'Does not accept IPv4 ranges' => [ '74.24.52.13/20', false ],
|
|
|
|
|
|
'Does not accept IPv6 ranges' => [ 'fc:100:a:d:1:e:ac:0/24', false ],
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideIPRanges
|
|
|
|
|
|
* @covers MediaWiki\User\UserNameUtils::isValidIPRange
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIsValidIPRange( $value, $result ) {
|
2021-07-27 11:41:13 +00:00
|
|
|
|
$utils = $this->getDummyUserNameUtils();
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
$this->assertSame(
|
|
|
|
|
|
$result,
|
|
|
|
|
|
$utils->isValidIPRange( $value )
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function provideIPRanges() {
|
|
|
|
|
|
return [
|
|
|
|
|
|
[ '116.17.184.5/32', true ],
|
|
|
|
|
|
[ '0.17.184.5/30', true ],
|
|
|
|
|
|
[ '16.17.184.1/24', true ],
|
|
|
|
|
|
[ '30.242.52.14/1', true ],
|
|
|
|
|
|
[ '10.232.52.13/8', true ],
|
|
|
|
|
|
[ '30.242.52.14/0', true ],
|
|
|
|
|
|
[ '::e:f:2001/96', true ],
|
|
|
|
|
|
[ '::c:f:2001/128', true ],
|
|
|
|
|
|
[ '::10:f:2001/70', true ],
|
|
|
|
|
|
[ '::fe:f:2001/1', true ],
|
|
|
|
|
|
[ '::6d:f:2001/8', true ],
|
|
|
|
|
|
[ '::fe:f:2001/0', true ],
|
|
|
|
|
|
[ '116.17.184.5/33', false ],
|
|
|
|
|
|
[ '0.17.184.5/130', false ],
|
|
|
|
|
|
[ '16.17.184.1/-1', false ],
|
|
|
|
|
|
[ '10.232.52.13/*', false ],
|
|
|
|
|
|
[ '7.232.52.13/ab', false ],
|
|
|
|
|
|
[ '11.232.52.13/', false ],
|
|
|
|
|
|
[ '::e:f:2001/129', false ],
|
|
|
|
|
|
[ '::c:f:2001/228', false ],
|
|
|
|
|
|
[ '::10:f:2001/-1', false ],
|
|
|
|
|
|
[ '::6d:f:2001/*', false ],
|
|
|
|
|
|
[ '::86:f:2001/ab', false ],
|
|
|
|
|
|
[ '::23:f:2001/', false ]
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-28 03:05:58 +00:00
|
|
|
|
public function testIsTemp() {
|
|
|
|
|
|
$utils = $this->getDummyUserNameUtils();
|
|
|
|
|
|
$this->assertFalse( $utils->isTemp( 'Some user' ) );
|
|
|
|
|
|
$this->assertTrue( $utils->isTemp( '*Unregistered 1234' ) );
|
|
|
|
|
|
$this->assertTrue( $utils->isTemp( '*1234' ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetTempPlaceholder() {
|
|
|
|
|
|
$utils = $this->getDummyUserNameUtils();
|
|
|
|
|
|
$name = $utils->getTempPlaceholder();
|
|
|
|
|
|
$this->assertSame( '*Unregistered *', $name );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-02-23 23:52:44 +00:00
|
|
|
|
}
|