18 $cache = new \HashBagOStuff();
19 $logger = $this->getMockBuilder( AbstractLogger::class )
20 ->setMethods( [
'log' ] )
21 ->getMockForAbstractClass();
24 [ [
'count' => 123,
'seconds' => 456 ] ],
25 [
'type' =>
'foo',
'cache' =>
$cache ]
27 $throttler->setLogger( $logger );
28 $throttlerPriv = \TestingAccessWrapper::newFromObject( $throttler );
29 $this->assertSame( [ [
'count' => 123,
'seconds' => 456 ] ], $throttlerPriv->conditions );
30 $this->assertSame(
'foo', $throttlerPriv->type );
31 $this->assertSame(
$cache, $throttlerPriv->cache );
32 $this->assertSame( $logger, $throttlerPriv->logger );
34 $throttler =
new Throttler( [ [
'count' => 123,
'seconds' => 456 ] ] );
35 $throttler->setLogger(
new NullLogger() );
36 $throttlerPriv = \TestingAccessWrapper::newFromObject( $throttler );
37 $this->assertSame( [ [
'count' => 123,
'seconds' => 456 ] ], $throttlerPriv->conditions );
38 $this->assertSame(
'custom', $throttlerPriv->type );
39 $this->assertInstanceOf( BagOStuff::class, $throttlerPriv->cache );
40 $this->assertInstanceOf( LoggerInterface::class, $throttlerPriv->logger );
42 $this->
setMwGlobals( [
'wgPasswordAttemptThrottle' => [ [
'count' => 321,
43 'seconds' => 654 ] ] ] );
45 $throttler->setLogger(
new NullLogger() );
46 $throttlerPriv = \TestingAccessWrapper::newFromObject( $throttler );
47 $this->assertSame( [ [
'count' => 321,
'seconds' => 654 ] ], $throttlerPriv->conditions );
48 $this->assertSame(
'password', $throttlerPriv->type );
49 $this->assertInstanceOf( BagOStuff::class, $throttlerPriv->cache );
50 $this->assertInstanceOf( LoggerInterface::class, $throttlerPriv->logger );
53 new Throttler( [], [
'foo' => 1,
'bar' => 2,
'baz' => 3 ] );
54 $this->fail(
'Expected exception not thrown' );
55 }
catch ( \InvalidArgumentException $ex ) {
56 $this->assertSame(
'unrecognized parameters: foo, bar, baz', $ex->getMessage() );
184 $cache = new \HashBagOStuff();
185 $throttler =
new Throttler( [ [
'count' => 1,
'seconds' => 10 ] ], [
'cache' =>
$cache ] );
187 $logger = $this->getMockBuilder( AbstractLogger::class )
188 ->setMethods( [
'log' ] )
189 ->getMockForAbstractClass();
190 $logger->expects( $this->never() )->method(
'log' );
191 $throttler->setLogger( $logger );
192 $result = $throttler->increase(
'SomeUser',
'1.2.3.4' );
193 $this->assertFalse(
$result,
'should not throttle' );
195 $logger = $this->getMockBuilder( AbstractLogger::class )
196 ->setMethods( [
'log' ] )
197 ->getMockForAbstractClass();
198 $logger->expects( $this->once() )->method(
'log' )->with( $this->
anything(), $this->
anything(), [
202 'username' =>
'SomeUser',
207 $throttler->setLogger( $logger );
208 $result = $throttler->increase(
'SomeUser',
'1.2.3.4',
'foo' );
209 $this->assertSame( [
'throttleIndex' => 0,
'count' => 1,
'wait' => 10 ],
$result );