Merge "User::isPingLimitable(): handle CIDR notation in $wgRateLimitsExcludedIPs"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 21 Feb 2017 18:34:15 +0000 (18:34 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 21 Feb 2017 18:34:15 +0000 (18:34 +0000)
1  2 
includes/DefaultSettings.php
tests/phpunit/includes/user/UserTest.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 = [];
@@@ -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
         */
                // 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() );
+       }
  }