}
public function testBasics() {
+ $user = $this->getMutableTestUser()->getUser();
+ $userName = $user->getName();
+ $lowerInitialUserName = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
+
$provider = new LocalPasswordPrimaryAuthenticationProvider();
$this->assertSame(
$provider->accountCreationType()
);
- $this->assertTrue( $provider->testUserExists( 'UTSysop' ) );
- $this->assertTrue( $provider->testUserExists( 'uTSysop' ) );
+ $this->assertTrue( $provider->testUserExists( $userName ) );
+ $this->assertTrue( $provider->testUserExists( $lowerInitialUserName ) );
$this->assertFalse( $provider->testUserExists( 'DoesNotExist' ) );
$this->assertFalse( $provider->testUserExists( '<invalid>' ) );
$provider->accountCreationType()
);
- $this->assertTrue( $provider->testUserExists( 'UTSysop' ) );
+ $this->assertTrue( $provider->testUserExists( $userName ) );
$this->assertFalse( $provider->testUserExists( 'DoesNotExist' ) );
$req = new PasswordAuthenticationRequest;
}
public function testTestUserCanAuthenticate() {
+ $user = $this->getMutableTestUser()->getUser();
+ $userName = $user->getName();
$dbw = wfGetDB( DB_MASTER );
- $oldHash = $dbw->selectField( 'user', 'user_password', [ 'user_name' => 'UTSysop' ] );
- $cb = new \ScopedCallback( function () use ( $dbw, $oldHash ) {
- $dbw->update( 'user', [ 'user_password' => $oldHash ], [ 'user_name' => 'UTSysop' ] );
- } );
- $id = \User::idFromName( 'UTSysop' );
$provider = $this->getProvider();
$this->assertFalse( $provider->testUserCanAuthenticate( 'DoesNotExist' ) );
- $this->assertTrue( $provider->testUserCanAuthenticate( 'UTSysop' ) );
- $this->assertTrue( $provider->testUserCanAuthenticate( 'uTSysop' ) );
+ $this->assertTrue( $provider->testUserCanAuthenticate( $userName ) );
+ $lowerInitialUserName = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
+ $this->assertTrue( $provider->testUserCanAuthenticate( $lowerInitialUserName ) );
$dbw->update(
'user',
[ 'user_password' => \PasswordFactory::newInvalidPassword()->toString() ],
- [ 'user_name' => 'UTSysop' ]
+ [ 'user_name' => $userName ]
);
- $this->assertFalse( $provider->testUserCanAuthenticate( 'UTSysop' ) );
+ $this->assertFalse( $provider->testUserCanAuthenticate( $userName ) );
// Really old format
$dbw->update(
'user',
[ 'user_password' => '0123456789abcdef0123456789abcdef' ],
- [ 'user_name' => 'UTSysop' ]
+ [ 'user_name' => $userName ]
);
- $this->assertTrue( $provider->testUserCanAuthenticate( 'UTSysop' ) );
+ $this->assertTrue( $provider->testUserCanAuthenticate( $userName ) );
}
public function testSetPasswordResetFlag() {
$provider->setManager( $this->manager );
$providerPriv = \TestingAccessWrapper::newFromObject( $provider );
+ $user = $this->getMutableTestUser()->getUser();
+ $userName = $user->getName();
$dbw = wfGetDB( DB_MASTER );
$row = $dbw->selectRow(
'user',
'*',
- [ 'user_name' => 'UTSysop' ],
+ [ 'user_name' => $userName ],
__METHOD__
);
$this->manager->removeAuthenticationSessionData( null );
$row->user_password_expires = wfTimestamp( TS_MW, time() + 200 );
- $providerPriv->setPasswordResetFlag( 'UTSysop', \Status::newGood(), $row );
+ $providerPriv->setPasswordResetFlag( $userName, \Status::newGood(), $row );
$this->assertNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
$this->manager->removeAuthenticationSessionData( null );
$row->user_password_expires = wfTimestamp( TS_MW, time() - 200 );
- $providerPriv->setPasswordResetFlag( 'UTSysop', \Status::newGood(), $row );
+ $providerPriv->setPasswordResetFlag( $userName, \Status::newGood(), $row );
$ret = $this->manager->getAuthenticationSessionData( 'reset-pass' );
$this->assertNotNull( $ret );
$this->assertSame( 'resetpass-expired', $ret->msg->getKey() );
$this->manager->removeAuthenticationSessionData( null );
$row->user_password_expires = wfTimestamp( TS_MW, time() - 1 );
- $providerPriv->setPasswordResetFlag( 'UTSysop', \Status::newGood(), $row );
+ $providerPriv->setPasswordResetFlag( $userName, \Status::newGood(), $row );
$ret = $this->manager->getAuthenticationSessionData( 'reset-pass' );
$this->assertNotNull( $ret );
$this->assertSame( 'resetpass-expired-soft', $ret->msg->getKey() );
$row->user_password_expires = null;
$status = \Status::newGood();
$status->error( 'testing' );
- $providerPriv->setPasswordResetFlag( 'UTSysop', $status, $row );
+ $providerPriv->setPasswordResetFlag( $userName, $status, $row );
$ret = $this->manager->getAuthenticationSessionData( 'reset-pass' );
$this->assertNotNull( $ret );
$this->assertSame( 'resetpass-validity-soft', $ret->msg->getKey() );
}
public function testAuthentication() {
+ $testUser = $this->getMutableTestUser();
+ $userName = $testUser->getUser()->getName();
+
$dbw = wfGetDB( DB_MASTER );
- $oldHash = $dbw->selectField( 'user', 'user_password', [ 'user_name' => 'UTSysop' ] );
- $cb = new \ScopedCallback( function () use ( $dbw, $oldHash ) {
- $dbw->update( 'user', [ 'user_password' => $oldHash ], [ 'user_name' => 'UTSysop' ] );
- } );
- $id = \User::idFromName( 'UTSysop' );
+ $id = \User::idFromName( $userName );
$req = new PasswordAuthenticationRequest();
$req->action = AuthManager::ACTION_LOGIN;
);
// Validation failure
- $req->username = 'UTSysop';
- $req->password = 'UTSysopPassword';
+ $req->username = $userName;
+ $req->password = $testUser->getPassword();
$this->validity = \Status::newFatal( 'arbitrary-failure' );
$ret = $provider->beginPrimaryAuthentication( $reqs );
$this->assertEquals(
$this->manager->removeAuthenticationSessionData( null );
$this->validity = \Status::newGood();
$this->assertEquals(
- AuthenticationResponse::newPass( 'UTSysop' ),
+ AuthenticationResponse::newPass( $userName ),
$provider->beginPrimaryAuthentication( $reqs )
);
$this->assertNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
// Successful auth after normalizing name
$this->manager->removeAuthenticationSessionData( null );
$this->validity = \Status::newGood();
- $req->username = 'uTSysop';
+ $req->username = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
$this->assertEquals(
- AuthenticationResponse::newPass( 'UTSysop' ),
+ AuthenticationResponse::newPass( $userName ),
$provider->beginPrimaryAuthentication( $reqs )
);
$this->assertNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
- $req->username = 'UTSysop';
+ $req->username = $userName;
// Successful auth with reset
$this->manager->removeAuthenticationSessionData( null );
$this->validity->error( 'arbitrary-warning' );
$this->assertEquals(
- AuthenticationResponse::newPass( 'UTSysop' ),
+ AuthenticationResponse::newPass( $userName ),
$provider->beginPrimaryAuthentication( $reqs )
);
$this->assertNotNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
// Correct handling of legacy encodings
$password = ':B:salt:' . md5( 'salt-' . md5( "\xe1\xe9\xed\xf3\xfa" ) );
- $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => 'UTSysop' ] );
+ $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => $userName ] );
$req->password = 'áéíóú';
$ret = $provider->beginPrimaryAuthentication( $reqs );
$this->assertEquals(
$this->config->set( 'LegacyEncoding', true );
$this->assertEquals(
- AuthenticationResponse::newPass( 'UTSysop' ),
+ AuthenticationResponse::newPass( $userName ),
$provider->beginPrimaryAuthentication( $reqs )
);
// Correct handling of really old password hashes
$this->config->set( 'PasswordSalt', false );
$password = md5( 'FooBar' );
- $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => 'UTSysop' ] );
+ $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => $userName ] );
$req->password = 'FooBar';
$this->assertEquals(
- AuthenticationResponse::newPass( 'UTSysop' ),
+ AuthenticationResponse::newPass( $userName ),
$provider->beginPrimaryAuthentication( $reqs )
);
$this->config->set( 'PasswordSalt', true );
$password = md5( "$id-" . md5( 'FooBar' ) );
- $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => 'UTSysop' ] );
+ $dbw->update( 'user', [ 'user_password' => $password ], [ 'user_name' => $userName ] );
$req->password = 'FooBar';
$this->assertEquals(
- AuthenticationResponse::newPass( 'UTSysop' ),
+ AuthenticationResponse::newPass( $userName ),
$provider->beginPrimaryAuthentication( $reqs )
);
/**
* @dataProvider provideProviderChangeAuthenticationData
- * @param string $user
+ * @param callable|bool $usernameTransform
* @param string $type
* @param bool $loginOnly
* @param bool $changed
*/
- public function testProviderChangeAuthenticationData( $user, $type, $loginOnly, $changed ) {
+ public function testProviderChangeAuthenticationData(
+ $usernameTransform, $type, $loginOnly, $changed ) {
+ $testUser = $this->getMutableTestUser();
+ $user = $testUser->getUser()->getName();
+ if ( is_callable( $usernameTransform ) ) {
+ $user = call_user_func( $usernameTransform, $user );
+ }
$cuser = ucfirst( $user );
- $oldpass = 'UTSysopPassword';
+ $oldpass = $testUser->getPassword();
$newpass = 'NewPassword';
$dbw = wfGetDB( DB_MASTER );
- $oldHash = $dbw->selectField( 'user', 'user_password', [ 'user_name' => $cuser ] );
$oldExpiry = $dbw->selectField( 'user', 'user_password_expires', [ 'user_name' => $cuser ] );
- $cb = new \ScopedCallback( function () use ( $dbw, $cuser, $oldHash, $oldExpiry ) {
- $dbw->update(
- 'user',
- [
- 'user_password' => $oldHash,
- 'user_password_expires' => $oldExpiry,
- ],
- [ 'user_name' => $cuser ]
- );
- } );
$this->mergeMwGlobalArrayValue( 'wgHooks', [
'ResetPasswordExpiration' => [ function ( $user, &$expires ) {
public static function provideProviderChangeAuthenticationData() {
return [
- [ 'UTSysop', AuthenticationRequest::class, false, false ],
- [ 'UTSysop', PasswordAuthenticationRequest::class, false, true ],
- [ 'UTSysop', AuthenticationRequest::class, true, false ],
- [ 'UTSysop', PasswordAuthenticationRequest::class, true, true ],
- [ 'uTSysop', PasswordAuthenticationRequest::class, false, true ],
- [ 'uTSysop', PasswordAuthenticationRequest::class, true, true ],
+ [ false, AuthenticationRequest::class, false, false ],
+ [ false, PasswordAuthenticationRequest::class, false, true ],
+ [ false, AuthenticationRequest::class, true, false ],
+ [ false, PasswordAuthenticationRequest::class, true, true ],
+ [ 'ucfirst', PasswordAuthenticationRequest::class, false, true ],
+ [ 'ucfirst', PasswordAuthenticationRequest::class, true, true ],
];
}
// We have to cheat a bit to avoid having to add a new user to
// the database to test the actual setting of the password works right
$dbw = wfGetDB( DB_MASTER );
- $oldHash = $dbw->selectField( 'user', 'user_password', [ 'user_name' => $user ] );
- $cb = new \ScopedCallback( function () use ( $dbw, $user, $oldHash ) {
- $dbw->update( 'user', [ 'user_password' => $oldHash ], [ 'user_name' => $user ] );
- } );
$user = \User::newFromName( 'UTSysop' );
$req->username = $user->getName();