Merge "Speed up password-handling in the unit tests"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 18 May 2016 12:46:28 +0000 (12:46 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 18 May 2016 12:46:28 +0000 (12:46 +0000)
1  2 
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/api/ApiLoginTest.php

@@@ -221,6 -221,9 +221,9 @@@ abstract class MediaWikiTestCase extend
                $defaultOverrides->set( 'ObjectCaches', $objectCaches );
                $defaultOverrides->set( 'MainCacheType', CACHE_NONE );
  
+               // Use a fast hash algorithm to hash passwords.
+               $defaultOverrides->set( 'PasswordDefault', 'A' );
                $testConfig = $customOverrides
                        ? new MultiConfig( [ $customOverrides, $defaultOverrides, $baseConfig ] )
                        : new MultiConfig( [ $defaultOverrides, $baseConfig ] );
                }
                $wgRequest = new FauxRequest();
                MediaWiki\Session\SessionManager::resetCache();
 +              MediaWiki\Auth\AuthManager::resetCache();
  
                $phpErrorLevel = intval( ini_get( 'error_reporting' ) );
  
@@@ -13,8 -13,6 +13,8 @@@ class ApiLoginTest extends ApiTestCase 
         * Test result of attempted login with an empty username
         */
        public function testApiLoginNoName() {
 +              global $wgDisableAuthManager;
 +
                $session = [
                        'wsTokenSecrets' => [ 'login' => 'foobar' ],
                ];
                        'lgname' => '', 'lgpassword' => self::$users['sysop']->password,
                        'lgtoken' => (string)( new MediaWiki\Session\Token( 'foobar', '' ) )
                ], $session );
 -              $this->assertEquals( 'NoName', $data[0]['login']['result'] );
 +              $this->assertEquals( $wgDisableAuthManager ? 'NoName' : 'Failed', $data[0]['login']['result'] );
        }
  
        public function testApiLoginBadPass() {
 -              global $wgServer;
 +              global $wgServer, $wgDisableAuthManager;
  
                $user = self::$users['sysop'];
                $user->getUser()->logout();
@@@ -63,7 -61,7 +63,7 @@@
                $this->assertNotInternalType( "bool", $result );
                $a = $result["login"]["result"];
  
 -              $this->assertEquals( "WrongPass", $a );
 +              $this->assertEquals( $wgDisableAuthManager ? 'WrongPass' : 'Failed', $a );
        }
  
        public function testApiLoginGoodPass() {
                $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( 'foobaz' );
+               $passwordHash = $passwordFactory->newFromPlaintext( 'foobaz' );
  
                $dbw = wfGetDB( DB_MASTER );
                $dbw->insert(
                        [
                                'bp_user' => $centralId,
                                'bp_app_id' => 'foo',
-                               'bp_password' => $pwhash->toString(),
+                               'bp_password' => $passwordHash->toString(),
                                'bp_token' => '',
                                'bp_restrictions' => MWRestrictions::newDefault()->toJson(),
                                'bp_grants' => '["test"]',