| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
use MediaWiki\Password\MWOldPassword; |
| 24 |
use MediaWiki\Password\Password; |
| 25 |
use MediaWiki\Password\PasswordError; |
| 26 |
use MediaWiki\Password\PasswordFactory; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class PasswordTest extends MediaWikiUnitTestCase { |
| 32 |
public function testNoTypeThrows() { |
| 33 |
$factory = new PasswordFactory(); |
| 34 |
$this->expectException( Exception::class ); |
| 35 |
$this->expectExceptionMessage( 'Password configuration must contain a type name' ); |
| 36 |
$this->getMockBuilder( Password::class ) |
| 37 |
->setConstructorArgs( [ $factory, [] ] ) |
| 38 |
->getMock(); |
| 39 |
} |
| 40 |
|
| 41 |
public function testGetType() { |
| 42 |
$factory = new PasswordFactory(); |
| 43 |
$password = new MWOldPassword( $factory, [ 'type' => 'this is a test' ] ); |
| 44 |
$this->assertSame( 'this is a test', $password->getType() ); |
| 45 |
} |
| 46 |
|
| 47 |
public function testToStringThrows() { |
| 48 |
$factory = new PasswordFactory(); |
| 49 |
$password = new MWOldPassword( $factory, [ 'type' => 'B' ], str_repeat( 'X', 300 ) ); |
| 50 |
$this->expectException( PasswordError::class ); |
| 51 |
$this->expectExceptionMessage( 'Password hash is too big' ); |
| 52 |
$password->toString(); |
| 53 |
} |
| 54 |
|
| 55 |
public function testToString() { |
| 56 |
$factory = new PasswordFactory(); |
| 57 |
$password = $this->getMockBuilder( Password::class ) |
| 58 |
->setConstructorArgs( [ $factory, [ 'type' => 'X' ], ':X:foo' ] ) |
| 59 |
->getMockForAbstractClass(); |
| 60 |
$this->assertSame( ':X:foo', $password->toString() ); |
| 61 |
} |
| 62 |
} |