X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fpassword%2FUserPasswordPolicyTest.php;h=5ea7b1d2a9550eb0c492382e2e58eda07ad3c775;hb=bdfa96eb726c9997a010f5a194eec71925bfddc2;hp=b419203f3497dfa7d45f9b6db07ebe4102b9c9a0;hpb=4618f70793d1178ca4c646ef397cf17b1cc70b44;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/password/UserPasswordPolicyTest.php b/tests/phpunit/includes/password/UserPasswordPolicyTest.php index b419203f34..5ea7b1d2a9 100644 --- a/tests/phpunit/includes/password/UserPasswordPolicyTest.php +++ b/tests/phpunit/includes/password/UserPasswordPolicyTest.php @@ -22,32 +22,32 @@ class UserPasswordPolicyTest extends MediaWikiTestCase { - protected $policies = array( - 'checkuser' => array( + protected $policies = [ + 'checkuser' => [ 'MinimalPasswordLength' => 10, 'MinimumPasswordLengthToLogin' => 6, 'PasswordCannotMatchUsername' => true, - ), - 'sysop' => array( + ], + 'sysop' => [ 'MinimalPasswordLength' => 8, 'MinimumPasswordLengthToLogin' => 1, 'PasswordCannotMatchUsername' => true, - ), - 'default' => array( + ], + 'default' => [ 'MinimalPasswordLength' => 4, 'MinimumPasswordLengthToLogin' => 1, 'PasswordCannotMatchBlacklist' => true, 'MaximalPasswordLength' => 4096, - ), - ); + ], + ]; - protected $checks = array( + protected $checks = [ 'MinimalPasswordLength' => 'PasswordPolicyChecks::checkMinimalPasswordLength', 'MinimumPasswordLengthToLogin' => 'PasswordPolicyChecks::checkMinimumPasswordLengthToLogin', 'PasswordCannotMatchUsername' => 'PasswordPolicyChecks::checkPasswordCannotMatchUsername', 'PasswordCannotMatchBlacklist' => 'PasswordPolicyChecks::checkPasswordCannotMatchBlacklist', 'MaximalPasswordLength' => 'PasswordPolicyChecks::checkMaximalPasswordLength', - ); + ]; private function getUserPasswordPolicy() { return new UserPasswordPolicy( $this->policies, $this->checks ); @@ -61,16 +61,17 @@ class UserPasswordPolicyTest extends MediaWikiTestCase { $upp = $this->getUserPasswordPolicy(); $user = User::newFromName( 'TestUserPolicy' ); + $user->addToDatabase(); $user->addGroup( 'sysop' ); $this->assertArrayEquals( - array( + [ 'MinimalPasswordLength' => 8, 'MinimumPasswordLengthToLogin' => 1, 'PasswordCannotMatchUsername' => 1, 'PasswordCannotMatchBlacklist' => true, 'MaximalPasswordLength' => 4096, - ), + ], $upp->getPoliciesForUser( $user ) ); } @@ -81,18 +82,18 @@ class UserPasswordPolicyTest extends MediaWikiTestCase { public function testGetPoliciesForGroups() { $effective = UserPasswordPolicy::getPoliciesForGroups( $this->policies, - array( 'user', 'checkuser' ), + [ 'user', 'checkuser' ], $this->policies['default'] ); $this->assertArrayEquals( - array( + [ 'MinimalPasswordLength' => 10, 'MinimumPasswordLengthToLogin' => 6, 'PasswordCannotMatchUsername' => true, 'PasswordCannotMatchBlacklist' => true, 'MaximalPasswordLength' => 4096, - ), + ], $effective ); } @@ -106,74 +107,75 @@ class UserPasswordPolicyTest extends MediaWikiTestCase { $upp = $this->getUserPasswordPolicy(); $user = User::newFromName( $username ); + $user->addToDatabase(); foreach ( $groups as $group ) { $user->addGroup( $group ); } $status = $upp->checkUserPassword( $user, $password ); $this->assertSame( $valid, $status->isGood(), $msg . ' - password valid' ); - $this->assertSame( $ok, $status->isOk(), $msg . ' - can login' ); + $this->assertSame( $ok, $status->isOK(), $msg . ' - can login' ); } public function provideCheckUserPassword() { - return array( - array( + return [ + [ 'PassPolicyUser', - array(), + [], '', false, false, 'No groups, default policy, password too short to login' - ), - array( + ], + [ 'PassPolicyUser', - array( 'user' ), + [ 'user' ], 'aaa', false, true, 'Default policy, short password' - ), - array( + ], + [ 'PassPolicyUser', - array( 'sysop' ), + [ 'sysop' ], 'abcdabcdabcd', true, true, 'Sysop with good password' - ), - array( + ], + [ 'PassPolicyUser', - array( 'sysop' ), + [ 'sysop' ], 'abcd', false, true, 'Sysop with short password' - ), - array( + ], + [ 'PassPolicyUser', - array( 'sysop', 'checkuser' ), + [ 'sysop', 'checkuser' ], 'abcdabcd', false, true, 'Checkuser with short password' - ), - array( + ], + [ 'PassPolicyUser', - array( 'sysop', 'checkuser' ), + [ 'sysop', 'checkuser' ], 'abcd', false, false, 'Checkuser with too short password to login' - ), - array( + ], + [ 'Useruser', - array( 'user' ), + [ 'user' ], 'Passpass', false, true, 'Username & password on blacklist' - ), - ); + ], + ]; } /** @@ -189,46 +191,46 @@ class UserPasswordPolicyTest extends MediaWikiTestCase { } public function provideMaxOfPolicies() { - return array( - array( - array( 'MinimalPasswordLength' => 8 ), // p1 - array( 'MinimalPasswordLength' => 2 ), // p2 - array( 'MinimalPasswordLength' => 8 ), // max + return [ + [ + [ 'MinimalPasswordLength' => 8 ], // p1 + [ 'MinimalPasswordLength' => 2 ], // p2 + [ 'MinimalPasswordLength' => 8 ], // max 'Basic max in p1' - ), - array( - array( 'MinimalPasswordLength' => 2 ), // p1 - array( 'MinimalPasswordLength' => 8 ), // p2 - array( 'MinimalPasswordLength' => 8 ), // max + ], + [ + [ 'MinimalPasswordLength' => 2 ], // p1 + [ 'MinimalPasswordLength' => 8 ], // p2 + [ 'MinimalPasswordLength' => 8 ], // max 'Basic max in p2' - ), - array( - array( 'MinimalPasswordLength' => 8 ), // p1 - array( + ], + [ + [ 'MinimalPasswordLength' => 8 ], // p1 + [ 'MinimalPasswordLength' => 2, 'PasswordCannotMatchUsername' => 1, - ), // p2 - array( + ], // p2 + [ 'MinimalPasswordLength' => 8, 'PasswordCannotMatchUsername' => 1, - ), // max + ], // max 'Missing items in p1' - ), - array( - array( + ], + [ + [ 'MinimalPasswordLength' => 8, 'PasswordCannotMatchUsername' => 1, - ), // p1 - array( + ], // p1 + [ 'MinimalPasswordLength' => 2, - ), // p2 - array( + ], // p2 + [ 'MinimalPasswordLength' => 8, 'PasswordCannotMatchUsername' => 1, - ), // max + ], // max 'Missing items in p2' - ), - ); + ], + ]; } }