From 1e25fb4e42c18089887f985adc9e86fe3ac3ba27 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 18 May 2016 12:54:18 -0400 Subject: [PATCH] Don't use deprecated User::checkPassword() in TestUser I423f09f added this call in an attempt to speed things up. However, User::checkPassword() was deprecated in I2c736ad7, and the call causes some tests to fail when $wgDisableAuthManager is false. Since this is trying to determine whether the user_password column in the user table needs updating for the unit test, let's test that directly instead of the much-more-complicated User::checkPassword(). Change-Id: I410de706f9074edea3f3988769a3e99231d8dca3 --- tests/phpunit/includes/TestUser.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/includes/TestUser.php b/tests/phpunit/includes/TestUser.php index 13bfa46a2f..247b6e4461 100644 --- a/tests/phpunit/includes/TestUser.php +++ b/tests/phpunit/includes/TestUser.php @@ -129,19 +129,28 @@ class TestUser { throw new MWException( "Passed User has not been added to the database yet!" ); } - if ( $user->checkPassword( $password ) === true ) { - return; // Nothing to do. - } - - $passwordFactory = new PasswordFactory(); - $passwordFactory->init( RequestContext::getMain()->getConfig() ); - $passwordHash = $passwordFactory->newFromPlaintext( $password ); - wfGetDB( DB_MASTER )->update( + $dbw = wfGetDB( DB_MASTER ); + $row = $dbw->selectRow( 'user', - [ 'user_password' => $passwordHash->toString() ], + [ 'user_password' ], [ 'user_id' => $user->getId() ], __METHOD__ ); + if ( !$row ) { + throw new MWException( "Passed User has an ID but is not in the database?" ); + } + + $passwordFactory = new PasswordFactory(); + $passwordFactory->init( RequestContext::getMain()->getConfig() ); + if ( !$passwordFactory->newFromCiphertext( $row->user_password )->equals( $password ) ) { + $passwordHash = $passwordFactory->newFromPlaintext( $password ); + $dbw->update( + 'user', + [ 'user_password' => $passwordHash->toString() ], + [ 'user_id' => $user->getId() ], + __METHOD__ + ); + } } /** -- 2.20.1