jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/335580 )
Change subject: User::isPingLimitable(): handle CIDR notation in
$wgRateLimitsExcludedIPs
......................................................................
User::isPingLimitable(): handle CIDR notation in $wgRateLimitsExcludedIPs
Bug: T156983
Change-Id: I727c19214cb3f9fad558d433bb38fbcf25d8497a
---
M includes/DefaultSettings.php
M includes/user/User.php
M tests/phpunit/includes/user/UserTest.php
3 files changed, 24 insertions(+), 2 deletions(-)
Approvals:
Reedy: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index c483366..5ecf17c 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -5681,7 +5681,7 @@
];
/**
- * 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 --git a/includes/user/User.php b/includes/user/User.php
index d0a2f92..1b32503 100644
--- a/includes/user/User.php
+++ b/includes/user/User.php
@@ -1862,7 +1862,7 @@
*/
public function isPingLimitable() {
global $wgRateLimitsExcludedIPs;
- if ( in_array( $this->getRequest()->getIP(),
$wgRateLimitsExcludedIPs ) ) {
+ if ( IP::isInRanges( $this->getRequest()->getIP(),
$wgRateLimitsExcludedIPs ) ) {
// No other good way currently to disable rate limits
// for specific IPs. :P
// But this is a crappy hack and should die.
diff --git a/tests/phpunit/includes/user/UserTest.php
b/tests/phpunit/includes/user/UserTest.php
index deb9708..615da2e 100644
--- a/tests/phpunit/includes/user/UserTest.php
+++ b/tests/phpunit/includes/user/UserTest.php
@@ -862,4 +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() );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/335580
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I727c19214cb3f9fad558d433bb38fbcf25d8497a
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits