MediaWiki  REL1_24
PasswordTestCase.php
Go to the documentation of this file.
00001 <?php
00026 abstract class PasswordTestCase extends MediaWikiTestCase {
00030     protected $passwordFactory;
00031 
00032     protected function setUp() {
00033         parent::setUp();
00034 
00035         $this->passwordFactory = new PasswordFactory();
00036         foreach ( $this->getTypeConfigs() as $type => $config ) {
00037             $this->passwordFactory->register( $type, $config );
00038         }
00039     }
00040 
00046     abstract protected function getTypeConfigs();
00047 
00055     abstract public static function providePasswordTests();
00056 
00060     public function testHashing( $shouldMatch, $hash, $password ) {
00061         $hash = $this->passwordFactory->newFromCiphertext( $hash );
00062         $password = $this->passwordFactory->newFromPlaintext( $password, $hash );
00063         $this->assertSame( $shouldMatch, $hash->equals( $password ) );
00064     }
00065 
00069     public function testStringSerialization( $shouldMatch, $hash, $password ) {
00070         $hashObj = $this->passwordFactory->newFromCiphertext( $hash );
00071         $serialized = $hashObj->toString();
00072         $unserialized = $this->passwordFactory->newFromCiphertext( $serialized );
00073         $this->assertTrue( $hashObj->equals( $unserialized ) );
00074     }
00075 
00081     public function testInvalidUnequalNormal( $shouldMatch, $hash, $password ) {
00082         $invalid = $this->passwordFactory->newFromCiphertext( null );
00083         $normal = $this->passwordFactory->newFromCiphertext( $hash );
00084 
00085         $this->assertFalse( $invalid->equals( $normal ) );
00086         $this->assertFalse( $normal->equals( $invalid ) );
00087     }
00088 }