X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fpassword%2FPasswordPolicyChecksTest.php;h=5ddbe271ebb1c13af2c077ed979e16632cbecce4;hb=e004a14a48579a87bdadb81147f83dbf0a876f34;hp=6357510f4ff48b7ba989d4c81277ade1d73f069f;hpb=75cdcc94007dca953927b13db411aac94750b074;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/password/PasswordPolicyChecksTest.php b/tests/phpunit/includes/password/PasswordPolicyChecksTest.php index 6357510f4f..5ddbe271eb 100644 --- a/tests/phpunit/includes/password/PasswordPolicyChecksTest.php +++ b/tests/phpunit/includes/password/PasswordPolicyChecksTest.php @@ -133,4 +133,44 @@ class PasswordPolicyChecksTest extends MediaWikiTestCase { $this->assertTrue( $statusLong->isOK(), 'Password matches blacklist, not fatal' ); } + public static function providePopularBlacklist() { + return [ + [ false, 'sitename' ], + [ false, 'password' ], + [ false, '12345' ], + [ true, 'hqY98gCZ6qM8s8' ], + ]; + } + + /** + * @covers PasswordPolicyChecks::checkPopularPasswordBlacklist + * @dataProvider providePopularBlacklist + */ + public function testCheckPopularPasswordBlacklist( $expected, $password ) { + global $IP; + $this->setMwGlobals( [ + 'wgSitename' => 'sitename', + 'wgPopularPasswordFile' => "$IP/serialized/commonpasswords.cdb" + ] ); + $user = User::newFromName( 'username' ); + $status = PasswordPolicyChecks::checkPopularPasswordBlacklist( PHP_INT_MAX, $user, $password ); + $this->assertSame( $expected, $status->isGood() ); + } + + /** + * Verify that all password policy description messages actually exist. + * Messages used on Special:PasswordPolicies + */ + public function testPasswordPolicyDescriptionsExist() { + global $wgPasswordPolicy; + $lang = Language::factory( 'en' ); + + foreach ( array_keys( $wgPasswordPolicy['checks'] ) as $check ) { + $msgKey = 'passwordpolicies-policy-' . strtolower( $check ); + $this->assertTrue( + wfMessage( $msgKey )->useDatabase( false )->inLanguage( $lang )->exists(), + "Message '$msgKey' required by '$check' must exist" + ); + } + } }