| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Password\Argon2Password; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class Argon2PasswordTest extends PasswordTestCase { |
| 12 |
|
| 13 |
protected function setUp(): void { |
| 14 |
parent::setUp(); |
| 15 |
if ( !defined( 'PASSWORD_ARGON2I' ) ) { |
| 16 |
$this->markTestSkipped( 'Argon2 support not found' ); |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
protected function getTypeConfigs() { |
| 26 |
return [ |
| 27 |
'argon2' => [ |
| 28 |
'class' => Argon2Password::class, |
| 29 |
'algo' => 'argon2i', |
| 30 |
'memory_cost' => 1024, |
| 31 |
'time_cost' => 2, |
| 32 |
'threads' => 2, |
| 33 |
] |
| 34 |
]; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public static function providePasswordTests() { |
| 41 |
return [ |
| 42 |
[ |
| 43 |
true, |
| 44 |
':argon2:$argon2i$v=19$m=1024,t=2,p=2$RHpGTXJPeFlSV2NDTEswNA$VeW7rumZY4pL8XO4KeQkKD43r5uX3eazVJRtrFN7lNc', |
| 45 |
'password', |
| 46 |
], |
| 47 |
[ |
| 48 |
true, |
| 49 |
':argon2:$argon2i$v=19$m=2048,t=5,p=3$MHFKSnh6WWZEWkpKa09SUQ$vU92h/8hkByL5VKW1P9amCj054pZILGKznAvKWAivZE', |
| 50 |
'password', |
| 51 |
], |
| 52 |
[ |
| 53 |
true, |
| 54 |
':argon2:$argon2i$v=19$m=1024,t=2,p=2$bFJ4TzM5RWh2T0VmeFhDTA$AHFUFZRh69aZYBqyxn6tpujpEcf2JP8wgRCPU3nw3W4', |
| 55 |
"pass\x00word", |
| 56 |
], |
| 57 |
[ |
| 58 |
false, |
| 59 |
':argon2:$argon2i$v=19$m=1024,t=2,p=2$UGZqTWJRUkI1alVNTGRUbA$RcASw9XUWjCDO9WNnuVkGkEylURUW/CcNwSffdFwN74', |
| 60 |
'password', |
| 61 |
], |
| 62 |
|
| 63 |
[ |
| 64 |
true, |
| 65 |
':argon2:$argon2id$v=19$m=65536,t=1,p=1$SS51Z0U2bkQ5Mk1GYUNQOQ$jdN3UnHn6MHOaOeWiX+RqRhcwVPLLDlEAKPvDt/qKIY', |
| 66 |
'password' |
| 67 |
] |
| 68 |
]; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public function testNeedsUpdate( $updateExpected, $hash ) { |
| 75 |
$password = $this->passwordFactory->newFromCiphertext( $hash ); |
| 76 |
$this->assertSame( $updateExpected, $password->needsUpdate() ); |
| 77 |
} |
| 78 |
|
| 79 |
public static function provideNeedsUpdate() { |
| 80 |
return [ |
| 81 |
[ false, ':argon2:$argon2i$v=19$m=1024,t=2,p=2$bFJ4TzM5RWh2T0VmeFhDTA$AHFUFZRh69aZYBqyxn6tpujpEcf2JP8wgRCPU3nw3W4' ], |
| 82 |
[ false, ':argon2:$argon2i$v=19$m=1024,t=2,p=2$<whatever>' ], |
| 83 |
[ true, ':argon2:$argon2i$v=19$m=666,t=2,p=2$<whatever>' ], |
| 84 |
[ true, ':argon2:$argon2i$v=19$m=1024,t=666,p=2$<whatever>' ], |
| 85 |
[ true, ':argon2:$argon2i$v=19$m=1024,t=2,p=666$<whatever>' ], |
| 86 |
]; |
| 87 |
} |
| 88 |
} |