Move MediaWikiPasswordTestCase to password dir
authoraddshore <addshorewiki@gmail.com>
Sat, 9 Aug 2014 00:16:43 +0000 (01:16 +0100)
committerLegoktm <legoktm.wikipedia@gmail.com>
Sat, 9 Aug 2014 00:40:06 +0000 (00:40 +0000)
Change-Id: I423e484929ce1bbc21e8f2ddd78196dee3520677

tests/TestsAutoLoader.php
tests/phpunit/MediaWikiPasswordTestCase.php [deleted file]
tests/phpunit/includes/password/BcryptPasswordTest.php
tests/phpunit/includes/password/LayeredParameterizedPasswordTest.php
tests/phpunit/includes/password/PasswordTestCase.php [new file with mode: 0644]
tests/phpunit/includes/password/Pbkdf2PasswordTest.php

index b56890b..0b7c6cf 100644 (file)
@@ -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 (file)
index edf944b..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-/**
- * Testing framework for the password hashes
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- */
-
-/**
- * @since 1.24
- */
-abstract class MediaWikiPasswordTestCase extends MediaWikiTestCase {
-       /**
-        * @var PasswordFactory
-        */
-       protected $passwordFactory;
-
-       protected function setUp() {
-               parent::setUp();
-
-               $this->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 ) );
-       }
-}
index b4d5f99..4d5c78a 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * @group large
  */
-class BcryptPasswordTestCase extends MediaWikiPasswordTestCase {
+class BcryptPasswordTestCase extends PasswordTestCase {
        protected function getTypeConfigs() {
                return array( 'bcrypt' => array(
                        'class' => 'BcryptPassword',
index c552253..03a742b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-class LayeredParameterizedPasswordTest extends MediaWikiPasswordTestCase {
+class LayeredParameterizedPasswordTest extends PasswordTestCase {
        protected function getTypeConfigs() {
                return array(
                        'testLargeLayeredTop' => array(
diff --git a/tests/phpunit/includes/password/PasswordTestCase.php b/tests/phpunit/includes/password/PasswordTestCase.php
new file mode 100644 (file)
index 0000000..7820d53
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/**
+ * Testing framework for the password hashes
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @since 1.24
+ */
+abstract class PasswordTestCase extends MediaWikiTestCase {
+       /**
+        * @var PasswordFactory
+        */
+       protected $passwordFactory;
+
+       protected function setUp() {
+               parent::setUp();
+
+               $this->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 ) );
+       }
+}
index c1b65d3..ae47120 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * @group large
  */
-class Pbkdf2PasswordTest extends MediaWikiPasswordTestCase {
+class Pbkdf2PasswordTest extends PasswordTestCase {
        protected function getTypeConfigs() {
                return array( 'pbkdf2' => array(
                        'class' => 'Pbkdf2Password',