Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / password / PasswordPolicyChecksTest.php
blob6357510f4ff48b7ba989d4c81277ade1d73f069f
1 <?php
2 /**
3 * Testing password-policy check functions
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
23 class PasswordPolicyChecksTest extends MediaWikiTestCase {
25 /**
26 * @covers PasswordPolicyChecks::checkMinimalPasswordLength
28 public function testCheckMinimalPasswordLength() {
29 $statusOK = PasswordPolicyChecks::checkMinimalPasswordLength(
30 3, // policy value
31 User::newFromName( 'user' ), // User
32 'password' // password
34 $this->assertTrue( $statusOK->isGood(), 'Password is longer than minimal policy' );
35 $statusShort = PasswordPolicyChecks::checkMinimalPasswordLength(
36 10, // policy value
37 User::newFromName( 'user' ), // User
38 'password' // password
40 $this->assertFalse(
41 $statusShort->isGood(),
42 'Password is shorter than minimal policy'
44 $this->assertTrue(
45 $statusShort->isOK(),
46 'Password is shorter than minimal policy, not fatal'
50 /**
51 * @covers PasswordPolicyChecks::checkMinimumPasswordLengthToLogin
53 public function testCheckMinimumPasswordLengthToLogin() {
54 $statusOK = PasswordPolicyChecks::checkMinimumPasswordLengthToLogin(
55 3, // policy value
56 User::newFromName( 'user' ), // User
57 'password' // password
59 $this->assertTrue( $statusOK->isGood(), 'Password is longer than minimal policy' );
60 $statusShort = PasswordPolicyChecks::checkMinimumPasswordLengthToLogin(
61 10, // policy value
62 User::newFromName( 'user' ), // User
63 'password' // password
65 $this->assertFalse(
66 $statusShort->isGood(),
67 'Password is shorter than minimum login policy'
69 $this->assertFalse(
70 $statusShort->isOK(),
71 'Password is shorter than minimum login policy, fatal'
75 /**
76 * @covers PasswordPolicyChecks::checkMaximalPasswordLength
78 public function testCheckMaximalPasswordLength() {
79 $statusOK = PasswordPolicyChecks::checkMaximalPasswordLength(
80 100, // policy value
81 User::newFromName( 'user' ), // User
82 'password' // password
84 $this->assertTrue( $statusOK->isGood(), 'Password is shorter than maximal policy' );
85 $statusLong = PasswordPolicyChecks::checkMaximalPasswordLength(
86 4, // policy value
87 User::newFromName( 'user' ), // User
88 'password' // password
90 $this->assertFalse( $statusLong->isGood(),
91 'Password is longer than maximal policy'
93 $this->assertFalse( $statusLong->isOK(),
94 'Password is longer than maximal policy, fatal'
98 /**
99 * @covers PasswordPolicyChecks::checkPasswordCannotMatchUsername
101 public function testCheckPasswordCannotMatchUsername() {
102 $statusOK = PasswordPolicyChecks::checkPasswordCannotMatchUsername(
103 1, // policy value
104 User::newFromName( 'user' ), // User
105 'password' // password
107 $this->assertTrue( $statusOK->isGood(), 'Password does not match username' );
108 $statusLong = PasswordPolicyChecks::checkPasswordCannotMatchUsername(
109 1, // policy value
110 User::newFromName( 'user' ), // User
111 'user' // password
113 $this->assertFalse( $statusLong->isGood(), 'Password matches username' );
114 $this->assertTrue( $statusLong->isOK(), 'Password matches username, not fatal' );
118 * @covers PasswordPolicyChecks::checkPasswordCannotMatchBlacklist
120 public function testCheckPasswordCannotMatchBlacklist() {
121 $statusOK = PasswordPolicyChecks::checkPasswordCannotMatchBlacklist(
122 true, // policy value
123 User::newFromName( 'Username' ), // User
124 'AUniquePassword' // password
126 $this->assertTrue( $statusOK->isGood(), 'Password is not on blacklist' );
127 $statusLong = PasswordPolicyChecks::checkPasswordCannotMatchBlacklist(
128 true, // policy value
129 User::newFromName( 'Useruser1' ), // User
130 'Passpass1' // password
132 $this->assertFalse( $statusLong->isGood(), 'Password matches blacklist' );
133 $this->assertTrue( $statusLong->isOK(), 'Password matches blacklist, not fatal' );