From: addshore Date: Sat, 9 Aug 2014 00:16:43 +0000 (+0100) Subject: Move MediaWikiPasswordTestCase to password dir X-Git-Tag: 1.31.0-rc.0~14508 X-Git-Url: http://git.cyclocoop.org/%27%20.generer_url_ecrire%28_request%28%27exec%27%29%2C%27cmd=switch&outil=rss_couteau_suisse%27%29.%27?a=commitdiff_plain;h=f479ccf7314b4c831c679815d84c01210bd31607;p=lhc%2Fweb%2Fwiklou.git Move MediaWikiPasswordTestCase to password dir Change-Id: I423e484929ce1bbc21e8f2ddd78196dee3520677 --- diff --git a/tests/TestsAutoLoader.php b/tests/TestsAutoLoader.php index b56890badb..0b7c6cf5d0 100644 --- a/tests/TestsAutoLoader.php +++ b/tests/TestsAutoLoader.php @@ -40,7 +40,6 @@ $wgAutoloadClasses += array( 'MediaWikiTestCase' => "$testDir/phpunit/MediaWikiTestCase.php", 'MediaWikiPHPUnitTestListener' => "$testDir/phpunit/MediaWikiPHPUnitTestListener.php", 'MediaWikiLangTestCase' => "$testDir/phpunit/MediaWikiLangTestCase.php", - 'MediaWikiPasswordTestCase' => "$testDir/phpunit/MediaWikiPasswordTestCase.php", 'ResourceLoaderTestCase' => "$testDir/phpunit/ResourceLoaderTestCase.php", 'ResourceLoaderTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php", 'ResourceLoaderFileModuleTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php", @@ -78,6 +77,9 @@ $wgAutoloadClasses += array( 'PageORMTableForTesting' => "$testDir/phpunit/includes/db/ORMTableTest.php", 'DatabaseTestHelper' => "$testDir/phpunit/includes/db/DatabaseTestHelper.php", + # tests/phpunit/includes/passwords + 'PasswordTestCase' => "$testDir/phpunit/includes/password/PasswordTestCase.php", + # tests/phpunit/languages 'LanguageClassesTestCase' => "$testDir/phpunit/languages/LanguageClassesTestCase.php", diff --git a/tests/phpunit/MediaWikiPasswordTestCase.php b/tests/phpunit/MediaWikiPasswordTestCase.php deleted file mode 100644 index edf944b47f..0000000000 --- a/tests/phpunit/MediaWikiPasswordTestCase.php +++ /dev/null @@ -1,88 +0,0 @@ -passwordFactory = new PasswordFactory(); - foreach ( $this->getTypeConfigs() as $type => $config ) { - $this->passwordFactory->register( $type, $config ); - } - } - - /** - * Return an array of configs to be used for this class's password type. - * - * @return array[] - */ - abstract protected function getTypeConfigs(); - - /** - * An array of tests in the form of (bool, string, string), where the first - * element is whether the second parameter (a password hash) and the third - * parameter (a password) should match. - * - * @return array - */ - abstract public function providePasswordTests(); - - /** - * @dataProvider providePasswordTests - */ - public function testHashing( $shouldMatch, $hash, $password ) { - $hash = $this->passwordFactory->newFromCiphertext( $hash ); - $password = $this->passwordFactory->newFromPlaintext( $password, $hash ); - $this->assertSame( $shouldMatch, $hash->equals( $password ) ); - } - - /** - * @dataProvider providePasswordTests - */ - public function testStringSerialization( $shouldMatch, $hash, $password ) { - $hashObj = $this->passwordFactory->newFromCiphertext( $hash ); - $serialized = $hashObj->toString(); - $unserialized = $this->passwordFactory->newFromCiphertext( $serialized ); - $this->assertTrue( $hashObj->equals( $unserialized ) ); - } - - /** - * @dataProvider providePasswordTests - * @covers InvalidPassword::equals - * @covers InvalidPassword::toString - */ - public function testInvalidUnequalNormal( $shouldMatch, $hash, $password ) { - $invalid = $this->passwordFactory->newFromCiphertext( null ); - $normal = $this->passwordFactory->newFromCiphertext( $hash ); - - $this->assertFalse( $invalid->equals( $normal ) ); - $this->assertFalse( $normal->equals( $invalid ) ); - } -} diff --git a/tests/phpunit/includes/password/BcryptPasswordTest.php b/tests/phpunit/includes/password/BcryptPasswordTest.php index b4d5f99691..4d5c78ac58 100644 --- a/tests/phpunit/includes/password/BcryptPasswordTest.php +++ b/tests/phpunit/includes/password/BcryptPasswordTest.php @@ -3,7 +3,7 @@ /** * @group large */ -class BcryptPasswordTestCase extends MediaWikiPasswordTestCase { +class BcryptPasswordTestCase extends PasswordTestCase { protected function getTypeConfigs() { return array( 'bcrypt' => array( 'class' => 'BcryptPassword', diff --git a/tests/phpunit/includes/password/LayeredParameterizedPasswordTest.php b/tests/phpunit/includes/password/LayeredParameterizedPasswordTest.php index c5522533a6..03a742bb81 100644 --- a/tests/phpunit/includes/password/LayeredParameterizedPasswordTest.php +++ b/tests/phpunit/includes/password/LayeredParameterizedPasswordTest.php @@ -1,6 +1,6 @@ array( diff --git a/tests/phpunit/includes/password/PasswordTestCase.php b/tests/phpunit/includes/password/PasswordTestCase.php new file mode 100644 index 0000000000..7820d535ff --- /dev/null +++ b/tests/phpunit/includes/password/PasswordTestCase.php @@ -0,0 +1,88 @@ +passwordFactory = new PasswordFactory(); + foreach ( $this->getTypeConfigs() as $type => $config ) { + $this->passwordFactory->register( $type, $config ); + } + } + + /** + * Return an array of configs to be used for this class's password type. + * + * @return array[] + */ + abstract protected function getTypeConfigs(); + + /** + * An array of tests in the form of (bool, string, string), where the first + * element is whether the second parameter (a password hash) and the third + * parameter (a password) should match. + * + * @return array + */ + abstract public function providePasswordTests(); + + /** + * @dataProvider providePasswordTests + */ + public function testHashing( $shouldMatch, $hash, $password ) { + $hash = $this->passwordFactory->newFromCiphertext( $hash ); + $password = $this->passwordFactory->newFromPlaintext( $password, $hash ); + $this->assertSame( $shouldMatch, $hash->equals( $password ) ); + } + + /** + * @dataProvider providePasswordTests + */ + public function testStringSerialization( $shouldMatch, $hash, $password ) { + $hashObj = $this->passwordFactory->newFromCiphertext( $hash ); + $serialized = $hashObj->toString(); + $unserialized = $this->passwordFactory->newFromCiphertext( $serialized ); + $this->assertTrue( $hashObj->equals( $unserialized ) ); + } + + /** + * @dataProvider providePasswordTests + * @covers InvalidPassword::equals + * @covers InvalidPassword::toString + */ + public function testInvalidUnequalNormal( $shouldMatch, $hash, $password ) { + $invalid = $this->passwordFactory->newFromCiphertext( null ); + $normal = $this->passwordFactory->newFromCiphertext( $hash ); + + $this->assertFalse( $invalid->equals( $normal ) ); + $this->assertFalse( $normal->equals( $invalid ) ); + } +} diff --git a/tests/phpunit/includes/password/Pbkdf2PasswordTest.php b/tests/phpunit/includes/password/Pbkdf2PasswordTest.php index c1b65d3c26..ae471207a5 100644 --- a/tests/phpunit/includes/password/Pbkdf2PasswordTest.php +++ b/tests/phpunit/includes/password/Pbkdf2PasswordTest.php @@ -3,7 +3,7 @@ /** * @group large */ -class Pbkdf2PasswordTest extends MediaWikiPasswordTestCase { +class Pbkdf2PasswordTest extends PasswordTestCase { protected function getTypeConfigs() { return array( 'pbkdf2' => array( 'class' => 'Pbkdf2Password',