5 use Wikimedia\TestingAccessWrapper;
16 $providerPriv = TestingAccessWrapper::newFromObject( $provider );
18 'AccountCreationThrottle' => [ [
22 'PasswordAttemptThrottle' => [ [
27 $provider->setConfig(
$config );
29 'accountCreationThrottle' => [ [
'count' => 123,
'seconds' => 86400 ] ],
30 'passwordAttemptThrottle' => [ [
'count' => 5,
'seconds' => 300 ] ]
31 ], $providerPriv->throttleSettings );
32 $accountCreationThrottle = TestingAccessWrapper::newFromObject(
33 $providerPriv->accountCreationThrottle );
34 $this->assertSame( [ [
'count' => 123,
'seconds' => 86400 ] ],
35 $accountCreationThrottle->conditions );
36 $passwordAttemptThrottle = TestingAccessWrapper::newFromObject(
37 $providerPriv->passwordAttemptThrottle );
38 $this->assertSame( [ [
'count' => 5,
'seconds' => 300 ] ],
39 $passwordAttemptThrottle->conditions );
42 'accountCreationThrottle' => [ [
'count' => 43,
'seconds' => 10000 ] ],
43 'passwordAttemptThrottle' => [ [
'count' => 11,
'seconds' => 100 ] ],
45 $providerPriv = TestingAccessWrapper::newFromObject( $provider );
47 'AccountCreationThrottle' => [ [
51 'PasswordAttemptThrottle' => [ [
56 $provider->setConfig(
$config );
58 'accountCreationThrottle' => [ [
'count' => 43,
'seconds' => 10000 ] ],
59 'passwordAttemptThrottle' => [ [
'count' => 11,
'seconds' => 100 ] ],
60 ], $providerPriv->throttleSettings );
62 $cache = new \HashBagOStuff();
64 $providerPriv = TestingAccessWrapper::newFromObject( $provider );
66 'AccountCreationThrottle' => [ [
'count' => 1,
'seconds' => 1 ] ],
67 'PasswordAttemptThrottle' => [ [
'count' => 1,
'seconds' => 1 ] ],
69 $accountCreationThrottle = TestingAccessWrapper::newFromObject(
70 $providerPriv->accountCreationThrottle );
71 $this->assertSame(
$cache, $accountCreationThrottle->cache );
72 $passwordAttemptThrottle = TestingAccessWrapper::newFromObject(
73 $providerPriv->passwordAttemptThrottle );
74 $this->assertSame(
$cache, $passwordAttemptThrottle->cache );
79 'accountCreationThrottle' => [],
80 'passwordAttemptThrottle' => [],
83 $provider->setLogger(
new \Psr\Log\NullLogger() );
85 'AccountCreationThrottle' =>
null,
86 'PasswordAttemptThrottle' =>
null,
92 $provider->testForAccountCreation(
100 $provider->testForAuthentication( [] )
112 'accountCreationThrottle' => [ [
'count' => 2,
'seconds' => 86400 ] ],
115 $provider->setLogger(
new \Psr\Log\NullLogger() );
117 'AccountCreationThrottle' =>
null,
118 'PasswordAttemptThrottle' =>
null,
126 ->setMethods( [
'onExemptFromAccountCreationThrottle' ] )
128 $mock->expects( $this->
any() )->method(
'onExemptFromAccountCreationThrottle' )
129 ->will( $this->returnValue(
false ) );
131 'ExemptFromAccountCreationThrottle' => [ $mock ],
137 $provider->testForAccountCreation(
$user, $creator, [] )->isOK(),
142 $provider->testForAccountCreation(
$user, $creator, [] )->isOK(),
146 $succeed ?
true :
false,
147 $provider->testForAccountCreation(
$user, $creator, [] )->isOK(),
154 'Normal user' => [
'NormalUser',
false,
false ],
155 'Sysop' => [
'UTSysop',
true,
false ],
156 'Normal user with hook' => [
'NormalUser',
true,
true ],
162 'passwordAttemptThrottle' => [ [
'count' => 2,
'seconds' => 86400 ] ],
165 $provider->setLogger(
new \Psr\Log\NullLogger() );
167 'AccountCreationThrottle' =>
null,
168 'PasswordAttemptThrottle' =>
null,
173 $req->username =
'SomeUser';
174 for ( $i = 1; $i <= 3; $i++ ) {
175 $status = $provider->testForAuthentication( [
$req ] );
176 $this->assertEquals( $i < 3, $status->isGood(),
"attempt #$i" );
178 $this->assertCount( 1,
$status->getErrors() );
179 $msg = new \Message(
$status->getErrors()[0][
'message'],
$status->getErrors()[0][
'params'] );
180 $this->assertEquals(
'login-throttled', $msg->getKey() );
184 $this->assertFalse( $provider->testForAuthentication( [
$req ] )->isGood(),
'after FAIL' );
188 $this->assertTrue( $provider->testForAuthentication( [
$req ] )->isGood(),
'after PASS' );
191 $req1->username =
'foo';
193 $req2->username =
'bar';
194 $this->assertTrue( $provider->testForAuthentication( [ $req1, $req2 ] )->isGood() );
197 $req->username =
'Some user';
198 $provider->testForAuthentication( [
$req ] );
199 $req->username =
'Some_user';
200 $provider->testForAuthentication( [
$req ] );
201 $req->username =
'some user';
202 $status = $provider->testForAuthentication( [
$req ] );
203 $this->assertFalse(
$status->isGood(),
'denormalized usernames are normalized' );
208 'passwordAttemptThrottle' => [],
213 'AccountCreationThrottle' =>
null,
214 'PasswordAttemptThrottle' =>
null,
221 'passwordAttemptThrottle' => [ [
'count' => 2,
'seconds' => 86400 ] ],
224 $logger = new \TestLogger(
true );
225 $provider->setLogger( $logger );
227 'AccountCreationThrottle' =>
null,
228 'PasswordAttemptThrottle' =>
null,
234 [ \Psr\Log\LogLevel::INFO,
'throttler data not found for {user}' ],
235 ], $logger->getBuffer() );