Don't use deprecated User::checkPassword() in TestUser
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 18 May 2016 16:54:18 +0000 (12:54 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 18 May 2016 16:57:05 +0000 (12:57 -0400)
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

index 13bfa46..247b6e4 100644 (file)
@@ -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__
+                       );
+               }
        }
 
        /**