5 use Wikimedia\TestingAccessWrapper;
15 $providerPriv = TestingAccessWrapper::newFromObject( $provider );
17 'AccountCreationThrottle' => [ [
21 'PasswordAttemptThrottle' => [ [
26 $provider->setConfig(
$config );
28 'accountCreationThrottle' => [ [
'count' => 123,
'seconds' => 86400 ] ],
29 'passwordAttemptThrottle' => [ [
'count' => 5,
'seconds' => 300 ] ]
30 ], $providerPriv->throttleSettings );
31 $accountCreationThrottle = TestingAccessWrapper::newFromObject(
32 $providerPriv->accountCreationThrottle );
33 $this->assertSame( [ [
'count' => 123,
'seconds' => 86400 ] ],
34 $accountCreationThrottle->conditions );
35 $passwordAttemptThrottle = TestingAccessWrapper::newFromObject(
36 $providerPriv->passwordAttemptThrottle );
37 $this->assertSame( [ [
'count' => 5,
'seconds' => 300 ] ],
38 $passwordAttemptThrottle->conditions );
41 'accountCreationThrottle' => [ [
'count' => 43,
'seconds' => 10000 ] ],
42 'passwordAttemptThrottle' => [ [
'count' => 11,
'seconds' => 100 ] ],
44 $providerPriv = TestingAccessWrapper::newFromObject( $provider );
46 'AccountCreationThrottle' => [ [
50 'PasswordAttemptThrottle' => [ [
55 $provider->setConfig(
$config );
57 'accountCreationThrottle' => [ [
'count' => 43,
'seconds' => 10000 ] ],
58 'passwordAttemptThrottle' => [ [
'count' => 11,
'seconds' => 100 ] ],
59 ], $providerPriv->throttleSettings );
61 $cache = new \HashBagOStuff();
63 $providerPriv = TestingAccessWrapper::newFromObject( $provider );
65 'AccountCreationThrottle' => [ [
'count' => 1,
'seconds' => 1 ] ],
66 'PasswordAttemptThrottle' => [ [
'count' => 1,
'seconds' => 1 ] ],
68 $accountCreationThrottle = TestingAccessWrapper::newFromObject(
69 $providerPriv->accountCreationThrottle );
70 $this->assertSame(
$cache, $accountCreationThrottle->cache );
71 $passwordAttemptThrottle = TestingAccessWrapper::newFromObject(
72 $providerPriv->passwordAttemptThrottle );
73 $this->assertSame(
$cache, $passwordAttemptThrottle->cache );
78 'accountCreationThrottle' => [],
79 'passwordAttemptThrottle' => [],
82 $provider->setLogger(
new \Psr\Log\NullLogger() );
84 'AccountCreationThrottle' =>
null,
85 'PasswordAttemptThrottle' =>
null,
91 $provider->testForAccountCreation(
99 $provider->testForAuthentication( [] )
111 'accountCreationThrottle' => [ [
'count' => 2,
'seconds' => 86400 ] ],
114 $provider->setLogger(
new \Psr\Log\NullLogger() );
116 'AccountCreationThrottle' =>
null,
117 'PasswordAttemptThrottle' =>
null,
124 $mock = $this->getMockBuilder(
'stdClass' )
125 ->setMethods( [
'onExemptFromAccountCreationThrottle' ] )
127 $mock->expects( $this->
any() )->method(
'onExemptFromAccountCreationThrottle' )
128 ->will( $this->returnValue(
false ) );
130 'ExemptFromAccountCreationThrottle' => [ $mock ],
136 $provider->testForAccountCreation(
$user, $creator, [] )->isOK(),
141 $provider->testForAccountCreation(
$user, $creator, [] )->isOK(),
145 $succeed ?
true :
false,
146 $provider->testForAccountCreation(
$user, $creator, [] )->isOK(),
153 'Normal user' => [
'NormalUser',
false,
false ],
154 'Sysop' => [
'UTSysop',
true,
false ],
155 'Normal user with hook' => [
'NormalUser',
true,
true ],
161 'passwordAttemptThrottle' => [ [
'count' => 2,
'seconds' => 86400 ] ],
164 $provider->setLogger(
new \Psr\Log\NullLogger() );
166 'AccountCreationThrottle' =>
null,
167 'PasswordAttemptThrottle' =>
null,
172 $req->username =
'SomeUser';
173 for ( $i = 1; $i <= 3; $i++ ) {
174 $status = $provider->testForAuthentication( [
$req ] );
175 $this->assertEquals( $i < 3, $status->isGood(),
"attempt #$i" );
177 $this->assertCount( 1,
$status->getErrors() );
178 $msg = new \Message(
$status->getErrors()[0][
'message'],
$status->getErrors()[0][
'params'] );
179 $this->assertEquals(
'login-throttled', $msg->getKey() );
183 $this->assertFalse( $provider->testForAuthentication( [
$req ] )->isGood(),
'after FAIL' );
187 $this->assertTrue( $provider->testForAuthentication( [
$req ] )->isGood(),
'after PASS' );
190 $req1->username =
'foo';
192 $req2->username =
'bar';
193 $this->assertTrue( $provider->testForAuthentication( [ $req1, $req2 ] )->isGood() );
196 $req->username =
'Some user';
197 $provider->testForAuthentication( [
$req ] );
198 $req->username =
'Some_user';
199 $provider->testForAuthentication( [
$req ] );
200 $req->username =
'some user';
201 $status = $provider->testForAuthentication( [
$req ] );
202 $this->assertFalse(
$status->isGood(),
'denormalized usernames are normalized' );
207 'passwordAttemptThrottle' => [],
212 'AccountCreationThrottle' =>
null,
213 'PasswordAttemptThrottle' =>
null,
220 'passwordAttemptThrottle' => [ [
'count' => 2,
'seconds' => 86400 ] ],
223 $logger = new \TestLogger(
true );
224 $provider->setLogger( $logger );
226 'AccountCreationThrottle' =>
null,
227 'PasswordAttemptThrottle' =>
null,
233 [ \Psr\Log\LogLevel::INFO,
'throttler data not found for {user}' ],
234 ], $logger->getBuffer() );