X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FTestUser.php;h=8b8cbcd4d9b62b8d93b82400ad0440f6df2f7ce7;hb=7586eef13a7da73401f1d200a3c99ea7c2ed1786;hp=b506cb87af01d939fb2f476a200bee3278381cdc;hpb=2a1fcd27c19913394c179cbe8be1a9e981d7f81b;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/TestUser.php b/tests/phpunit/includes/TestUser.php index b506cb87af..8b8cbcd4d9 100644 --- a/tests/phpunit/includes/TestUser.php +++ b/tests/phpunit/includes/TestUser.php @@ -78,6 +78,12 @@ class TestUser { $this->user->removeGroup( $group ); } if ( $change ) { + // Disable CAS check before saving. The User object may have been initialized from cached + // information that may be out of whack with the database during testing. If tests were + // perfectly isolated, this would not happen. But if it does happen, let's just ignore the + // inconsistency, and just write the data we want - during testing, we are not worried + // about data loss. + $this->user->mTouched = ''; $this->user->saveSettings(); } } @@ -129,20 +135,32 @@ class TestUser { throw new MWException( "Passed User has not been added to the database yet!" ); } - $passwordFactory = new PasswordFactory(); - $passwordFactory->init( RequestContext::getMain()->getConfig() ); - // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only - $passwordFactory->setDefaultType( 'A' ); - $pwhash = $passwordFactory->newFromPlaintext( $password ); - wfGetDB( DB_MASTER )->update( + $dbw = wfGetDB( DB_MASTER ); + $row = $dbw->selectRow( 'user', - [ 'user_password' => $pwhash->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__ + ); + } } /** + * @since 1.25 * @return User */ public function getUser() { @@ -150,6 +168,7 @@ class TestUser { } /** + * @since 1.25 * @return string */ public function getPassword() {