AuthManager is coming, which will make it easier to add alternative methods of authentication. But in order to do that, we need to finally get around to ripping the password-related bits out of the User class. The password expiration handling isn't used anywhere in core or extensions in Gerrit beyond testing for expired passwords on login and resetting the expiry date on password change. Those bits have been inlined and the functions removed; AuthManager will allow each "authentication provider" to handle its own password expiration. The methods for fetching passwords, including the fact that mPassword and other fields are public, has also been removed. This is already broken in combination with basically any extension that messes with authentication, and the major use outside of that was in creating system users like MassMessage's "MediaWiki message delivery" user. Password setting methods are silently deprecated, since most of the replacements won't be available until AuthManager. But uses in unit testing can be replaced with TestUser::setPasswordForUser() immediately. User::randomPassword() and User::getPasswordFactory() don't really belong in User either. For the former a new PasswordFactory method has been created, while the latter should just be replaced by the two lines to create a PasswordFactory via its constructor. Bug: T47716 Change-Id: I2c736ad72d946fa9b859e6cd335fa58aececc0d5
100 lines
2.8 KiB
PHP
100 lines
2.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group Database
|
|
* @group Cache
|
|
*/
|
|
class GenderCacheTest extends MediaWikiLangTestCase {
|
|
|
|
function addDBData() {
|
|
// ensure the correct default gender
|
|
$this->mergeMwGlobalArrayValue( 'wgDefaultUserOptions', array( 'gender' => 'unknown' ) );
|
|
|
|
$user = User::newFromName( 'UTMale' );
|
|
if ( $user->getID() == 0 ) {
|
|
$user->addToDatabase();
|
|
TestUser::setPasswordForUser( $user, 'UTMalePassword' );
|
|
}
|
|
// ensure the right gender
|
|
$user->setOption( 'gender', 'male' );
|
|
$user->saveSettings();
|
|
|
|
$user = User::newFromName( 'UTFemale' );
|
|
if ( $user->getID() == 0 ) {
|
|
$user->addToDatabase();
|
|
TestUser::setPasswordForUser( $user, 'UTFemalePassword' );
|
|
}
|
|
// ensure the right gender
|
|
$user->setOption( 'gender', 'female' );
|
|
$user->saveSettings();
|
|
|
|
$user = User::newFromName( 'UTDefaultGender' );
|
|
if ( $user->getID() == 0 ) {
|
|
$user->addToDatabase();
|
|
TestUser::setPasswordForUser( $user, 'UTDefaultGenderPassword' );
|
|
}
|
|
// ensure the default gender
|
|
$user->setOption( 'gender', null );
|
|
$user->saveSettings();
|
|
}
|
|
|
|
/**
|
|
* test usernames
|
|
*
|
|
* @dataProvider provideUserGenders
|
|
* @covers GenderCache::getGenderOf
|
|
*/
|
|
public function testUserName( $username, $expectedGender ) {
|
|
$genderCache = GenderCache::singleton();
|
|
$gender = $genderCache->getGenderOf( $username );
|
|
$this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
|
|
}
|
|
|
|
/**
|
|
* genderCache should work with user objects, too
|
|
*
|
|
* @dataProvider provideUserGenders
|
|
* @covers GenderCache::getGenderOf
|
|
*/
|
|
public function testUserObjects( $username, $expectedGender ) {
|
|
$genderCache = GenderCache::singleton();
|
|
$user = User::newFromName( $username );
|
|
$gender = $genderCache->getGenderOf( $user );
|
|
$this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
|
|
}
|
|
|
|
public static function provideUserGenders() {
|
|
return array(
|
|
array( 'UTMale', 'male' ),
|
|
array( 'UTFemale', 'female' ),
|
|
array( 'UTDefaultGender', 'unknown' ),
|
|
array( 'UTNotExist', 'unknown' ),
|
|
// some not valid user
|
|
array( '127.0.0.1', 'unknown' ),
|
|
array( 'user@test', 'unknown' ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* test strip of subpages to avoid unnecessary queries
|
|
* against the never existing username
|
|
*
|
|
* @dataProvider provideStripSubpages
|
|
* @covers GenderCache::getGenderOf
|
|
*/
|
|
public function testStripSubpages( $pageWithSubpage, $expectedGender ) {
|
|
$genderCache = GenderCache::singleton();
|
|
$gender = $genderCache->getGenderOf( $pageWithSubpage );
|
|
$this->assertEquals( $gender, $expectedGender, "GenderCache must strip of subpages" );
|
|
}
|
|
|
|
public static function provideStripSubpages() {
|
|
return array(
|
|
array( 'UTMale/subpage', 'male' ),
|
|
array( 'UTFemale/subpage', 'female' ),
|
|
array( 'UTDefaultGender/subpage', 'unknown' ),
|
|
array( 'UTNotExist/subpage', 'unknown' ),
|
|
array( '127.0.0.1/subpage', 'unknown' ),
|
|
);
|
|
}
|
|
}
|