| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Password\BcryptPassword; |
| 4 |
use MediaWiki\Password\LayeredParameterizedPassword; |
| 5 |
use MediaWiki\Password\ParameterizedPassword; |
| 6 |
use MediaWiki\Password\Pbkdf2PasswordUsingHashExtension; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class LayeredParameterizedPasswordTest extends PasswordTestCase { |
| 13 |
protected function getTypeConfigs() { |
| 14 |
return [ |
| 15 |
'testLargeLayeredTop' => [ |
| 16 |
'class' => LayeredParameterizedPassword::class, |
| 17 |
'types' => [ |
| 18 |
'testLargeLayeredBottom', |
| 19 |
'testLargeLayeredBottom', |
| 20 |
'testLargeLayeredBottom', |
| 21 |
'testLargeLayeredBottom', |
| 22 |
'testLargeLayeredFinal', |
| 23 |
], |
| 24 |
], |
| 25 |
'testLargeLayeredBottom' => [ |
| 26 |
'class' => Pbkdf2PasswordUsingHashExtension::class, |
| 27 |
'algo' => 'sha512', |
| 28 |
'cost' => 1024, |
| 29 |
'length' => 512, |
| 30 |
], |
| 31 |
'testLargeLayeredFinal' => [ |
| 32 |
'class' => BcryptPassword::class, |
| 33 |
'cost' => 5, |
| 34 |
] |
| 35 |
]; |
| 36 |
} |
| 37 |
|
| 38 |
protected function getValidTypes() { |
| 39 |
return [ 'testLargeLayeredFinal' ]; |
| 40 |
} |
| 41 |
|
| 42 |
public static function providePasswordTests() { |
| 43 |
return [ |
| 44 |
[ |
| 45 |
true, |
| 46 |
':testLargeLayeredTop:sha512:1024:512!sha512:1024:512!sha512:1024:512!sha512:1024:512!5!vnRy+2SrSA0fHt3dwhTP5g==!AVnwfZsAQjn+gULv7FSGjA==!xvHUX3WcpkeSn1lvjWcvBg==!It+OC/N9tu+d3ByHhuB0BQ==!Tb.gqUOiD.aWktVwHM.Q/O!7CcyMfXUPky5ptyATJsR2nq3vUqtnBC', |
| 47 |
'testPassword123' |
| 48 |
], |
| 49 |
]; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
public function testLargeLayeredPartialUpdate() { |
| 54 |
|
| 55 |
$partialPassword = $this->passwordFactory->newFromType( 'testLargeLayeredBottom' ); |
| 56 |
$partialPassword->crypt( 'testPassword123' ); |
| 57 |
|
| 58 |
|
| 59 |
$totalPassword = $this->passwordFactory->newFromType( 'testLargeLayeredTop' ); |
| 60 |
$totalPassword->partialCrypt( $partialPassword ); |
| 61 |
|
| 62 |
$this->assertTrue( $totalPassword->verify( 'testPassword123' ) ); |
| 63 |
} |
| 64 |
} |