$this->setUpPermissionGlobals();
- $this->user = new User;
- $this->user->addToDatabase();
- $this->user->addGroup( 'unittesters' );
+ $this->user = $this->getTestUser( [ 'unittesters' ] )->getUser();
}
private function setUpPermissionGlobals() {
* @covers User::getRights
*/
public function testUserGetRightsHooks() {
- $user = new User;
- $user->addToDatabase();
- $user->addGroup( 'unittesters' );
- $user->addGroup( 'testwriters' );
+ $user = $this->getTestUser( [ 'unittesters', 'testwriters' ] )->getUser();
$userWrapper = TestingAccessWrapper::newFromObject( $user );
$rights = $user->getRights();
[ 'Ab/cd', false, 'Contains slash' ],
[ 'Ab cd', true, 'Whitespace' ],
[ '192.168.1.1', false, 'IP' ],
+ [ '116.17.184.5/32', false, 'IP range' ],
+ [ '::e:f:2001/96', false, 'IPv6 range' ],
[ 'User:Abcd', false, 'Reserved Namespace' ],
[ '12abcd232', true, 'Starts with Numbers' ],
[ '?abcd', true, 'Start with ? mark' ],
$this->assertFalse( $user->getExperienceLevel() );
}
+
+ public static function provideIsLocallBlockedProxy() {
+ return [
+ [ '1.2.3.4', '1.2.3.4' ],
+ [ '1.2.3.4', '1.2.3.0/16' ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideIsLocallBlockedProxy
+ * @covers User::isLocallyBlockedProxy
+ */
+ public function testIsLocallyBlockedProxy( $ip, $blockListEntry ) {
+ $this->setMwGlobals(
+ 'wgProxyList', []
+ );
+ $this->assertFalse( User::isLocallyBlockedProxy( $ip ) );
+
+ $this->setMwGlobals(
+ 'wgProxyList',
+ [
+ $blockListEntry
+ ]
+ );
+ $this->assertTrue( User::isLocallyBlockedProxy( $ip ) );
+
+ $this->setMwGlobals(
+ 'wgProxyList',
+ [
+ 'test' => $blockListEntry
+ ]
+ );
+ $this->assertTrue( User::isLocallyBlockedProxy( $ip ) );
+
+ $this->hideDeprecated(
+ 'IP addresses in the keys of $wgProxyList (found the following IP ' .
+ 'addresses in keys: ' . $blockListEntry . ', please move them to values)'
+ );
+ $this->setMwGlobals(
+ 'wgProxyList',
+ [
+ $blockListEntry => 'test'
+ ]
+ );
+ $this->assertTrue( User::isLocallyBlockedProxy( $ip ) );
+ }
}