From: jenkins-bot Date: Tue, 21 Feb 2017 18:34:15 +0000 (+0000) Subject: Merge "User::isPingLimitable(): handle CIDR notation in $wgRateLimitsExcludedIPs" X-Git-Tag: 1.31.0-rc.0~4036 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=698fa7d8beff267c56292b476b3fe434165cc273;hp=-c;p=lhc%2Fweb%2Fwiklou.git Merge "User::isPingLimitable(): handle CIDR notation in $wgRateLimitsExcludedIPs" --- 698fa7d8beff267c56292b476b3fe434165cc273 diff --combined includes/DefaultSettings.php index 791d024af6,5ecf17cb26..c64f5509e9 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@@ -4786,7 -4786,6 +4786,7 @@@ $wgReservedUsernames = 'Maintenance script', // Maintenance scripts which perform editing, image import script 'Template namespace initialisation script', // Used in 1.2->1.3 upgrade 'ScriptImporter', // Default user name used by maintenance/importSiteScripts.php + 'Unknown user', // Used in WikiImporter when importing revisions with no author 'msg:double-redirect-fixer', // Automatic double redirect fix 'msg:usermessage-editor', // Default user for leaving user messages 'msg:proxyblocker', // For $wgProxyList and Special:Blockme (removed in 1.22) @@@ -5682,7 -5681,7 +5682,7 @@@ $wgRateLimits = ]; /** - * Array of IPs which should be excluded from rate limits. + * Array of IPs / CIDR ranges which should be excluded from rate limits. * This may be useful for whitelisting NAT gateways for conferences, etc. */ $wgRateLimitsExcludedIPs = []; diff --combined tests/phpunit/includes/user/UserTest.php index 941e940d42,615da2ecef..65b49ba2da --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@@ -362,7 -362,7 +362,7 @@@ class UserTest extends MediaWikiTestCas } /** - * Bug 37963 + * T39963 * Make sure defaults are loaded when setOption is called. * @covers User::loadOptions */ @@@ -862,4 -862,26 +862,26 @@@ // Clean up. $block->delete(); } + + public function testIsPingLimitable() { + $request = new FauxRequest(); + $request->setIP( '1.2.3.4' ); + $user = User::newFromSession( $request ); + + $this->setMwGlobals( 'wgRateLimitsExcludedIPs', [] ); + $this->assertTrue( $user->isPingLimitable() ); + + $this->setMwGlobals( 'wgRateLimitsExcludedIPs', [ '1.2.3.4' ] ); + $this->assertFalse( $user->isPingLimitable() ); + + $this->setMwGlobals( 'wgRateLimitsExcludedIPs', [ '1.2.3.0/8' ] ); + $this->assertFalse( $user->isPingLimitable() ); + + $this->setMwGlobals( 'wgRateLimitsExcludedIPs', [] ); + $noRateLimitUser = $this->getMockBuilder( User::class )->disableOriginalConstructor() + ->setMethods( [ 'getIP', 'getRights' ] )->getMock(); + $noRateLimitUser->expects( $this->any() )->method( 'getIP' )->willReturn( '1.2.3.4' ); + $noRateLimitUser->expects( $this->any() )->method( 'getRights' )->willReturn( [ 'noratelimit' ] ); + $this->assertFalse( $noRateLimitUser->isPingLimitable() ); + } }