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