http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94932
Revision: 94932 Author: ialex Date: 2011-08-18 20:03:30 +0000 (Thu, 18 Aug 2011) Log Message: ----------- Moved wfGetIP() to WebRequest::getIP(): * Changed all calls in core to the latter * Also marked wfGetForwardedFor() as deprecated * Moved wfGetIP() tests to WebRequestTest Modified Paths: -------------- trunk/phase3/api.php trunk/phase3/includes/Autopromote.php trunk/phase3/includes/EditPage.php trunk/phase3/includes/Exception.php trunk/phase3/includes/ProxyTools.php trunk/phase3/includes/RecentChange.php trunk/phase3/includes/SkinLegacy.php trunk/phase3/includes/Title.php trunk/phase3/includes/User.php trunk/phase3/includes/WebRequest.php trunk/phase3/includes/specials/SpecialBlockme.php trunk/phase3/includes/specials/SpecialPasswordReset.php trunk/phase3/includes/specials/SpecialUserlogin.php trunk/phase3/includes/specials/SpecialVersion.php trunk/phase3/tests/phpunit/includes/WebRequestTest.php Removed Paths: ------------- trunk/phase3/tests/phpunit/includes/ProxyTools/ Modified: trunk/phase3/api.php =================================================================== --- trunk/phase3/api.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/api.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -127,7 +127,7 @@ $items = array( wfTimestamp( TS_MW ), $endtime - $starttime, - wfGetIP(), + $wgRequest->getIP(), $_SERVER['HTTP_USER_AGENT'] ); $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET'; Modified: trunk/phase3/includes/Autopromote.php =================================================================== --- trunk/phase3/includes/Autopromote.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/Autopromote.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -166,9 +166,9 @@ $groups = array_slice( $cond, 1 ); return count( array_intersect( $groups, $user->getGroups() ) ) == count( $groups ); case APCOND_ISIP: - return $cond[1] == wfGetIP(); + return $cond[1] == $user->getRequest()->getIP(); case APCOND_IPINRANGE: - return IP::isInRange( wfGetIP(), $cond[1] ); + return IP::isInRange( $user->getRequest()->getIP(), $cond[1] ); case APCOND_BLOCKED: return $user->isBlocked(); case APCOND_ISBOT: Modified: trunk/phase3/includes/EditPage.php =================================================================== --- trunk/phase3/includes/EditPage.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/EditPage.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -856,7 +856,7 @@ * @return int one of the constants describing the result */ function internalAttemptSave( &$result, $bot = false ) { - global $wgFilterCallback, $wgUser, $wgParser; + global $wgFilterCallback, $wgUser, $wgRequest, $wgParser; global $wgMaxArticleSize; wfProfileIn( __METHOD__ ); @@ -888,7 +888,7 @@ } if ( $match !== false ) { $result['spam'] = $match; - $ip = wfGetIP(); + $ip = $wgRequest->getIP(); $pdbk = $this->mTitle->getPrefixedDBkey(); $match = str_replace( "\n", '', $match ); wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" ); Modified: trunk/phase3/includes/Exception.php =================================================================== --- trunk/phase3/includes/Exception.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/Exception.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -352,7 +352,7 @@ */ class UserBlockedError extends ErrorPageError { public function __construct( Block $block ){ - global $wgLang; + global $wgLang, $wgRequest; $blockerUserpage = $block->getBlocker()->getUserPage(); $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]"; @@ -372,7 +372,7 @@ array( $link, $reason, - wfGetIP(), + $wgRequest->getIP(), $block->getBlocker()->getName(), $block->getId(), $wgLang->formatExpiry( $block->mExpiry ), Modified: trunk/phase3/includes/ProxyTools.php =================================================================== --- trunk/phase3/includes/ProxyTools.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/ProxyTools.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -8,29 +8,13 @@ /** * Extracts the XFF string from the request header * Note: headers are spoofable + * + * @deprecated in 1.19; use $wgRequest->getHeader( 'X-Forwarded-For' ) instead. * @return string */ function wfGetForwardedFor() { - $apacheHeaders = function_exists( 'apache_request_headers' ) ? apache_request_headers() : null; - if( is_array( $apacheHeaders ) ) { - // More reliable than $_SERVER due to case and -/_ folding - $set = array(); - foreach ( $apacheHeaders as $tempName => $tempValue ) { - $set[ strtoupper( $tempName ) ] = $tempValue; - } - $index = strtoupper ( 'X-Forwarded-For' ); - } else { - // Subject to spoofing with headers like X_Forwarded_For - $set = $_SERVER; - $index = 'HTTP_X_FORWARDED_FOR'; - } - - #Try to see if XFF is set - if( isset( $set[$index] ) ) { - return $set[$index]; - } else { - return null; - } + global $wgRequest; + return $wgRequest->getHeader( 'X-Forwarded-For' ); } /** @@ -42,88 +26,20 @@ */ function wfGetAgent() { wfDeprecated( __FUNCTION__ ); - if( function_exists( 'apache_request_headers' ) ) { - // More reliable than $_SERVER due to case and -/_ folding - $set = array(); - foreach ( apache_request_headers() as $tempName => $tempValue ) { - $set[ strtoupper( $tempName ) ] = $tempValue; - } - $index = strtoupper ( 'User-Agent' ); - } else { - // Subject to spoofing with headers like X_Forwarded_For - $set = $_SERVER; - $index = 'HTTP_USER_AGENT'; - } - if( isset( $set[$index] ) ) { - return $set[$index]; - } else { - return ''; - } + global $wgRequest; + return $wgRequest->getHeader( 'User-Agent' ); } /** * Work out the IP address based on various globals * For trusted proxies, use the XFF client IP (first of the chain) - * @param $reset boolean Used to reset the internal static variable - * tracking the IP address. Set to anything non empty to reset it, for - * example: wfGetIP( 'reset' ); (default: false). + * + * @deprecated in 1.19; call $wgRequest->getIP() directly. * @return string */ -function wfGetIP( $reset = false ) { - global $wgUsePrivateIPs, $wgCommandLineMode; - static $ip = false; - - if( $reset ) { - $ip = false; - } - - # Return cached result - if ( !empty( $ip ) ) { - return $ip; - } - - /* collect the originating ips */ - # Client connecting to this webserver - if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { - $ip = IP::canonicalize( $_SERVER['REMOTE_ADDR'] ); - } elseif( $wgCommandLineMode ) { - $ip = '127.0.0.1'; - } - - # Append XFF - $forwardedFor = wfGetForwardedFor(); - if ( $forwardedFor !== null ) { - $ipchain = array_map( 'trim', explode( ',', $forwardedFor ) ); - $ipchain = array_reverse( $ipchain ); - if ( $ip ) { - array_unshift( $ipchain, $ip ); - } - - # Step through XFF list and find the last address in the list which is a trusted server - # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private) - foreach ( $ipchain as $i => $curIP ) { - $curIP = IP::canonicalize( $curIP ); - if ( wfIsTrustedProxy( $curIP ) ) { - if ( isset( $ipchain[$i + 1] ) ) { - if( $wgUsePrivateIPs || IP::isPublic( $ipchain[$i + 1 ] ) ) { - $ip = $ipchain[$i + 1]; - } - } - } else { - break; - } - } - } - - # Allow extensions to improve our guess - wfRunHooks( 'GetIP', array( &$ip ) ); - - if( !$ip ) { - throw new MWException( "Unable to determine IP" ); - } - - wfDebug( "IP: $ip\n" ); - return $ip; +function wfGetIP() { + global $wgRequest; + return $wgRequest->getIP(); } /** @@ -148,14 +64,14 @@ */ function wfProxyCheck() { global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath; - global $wgMemc, $wgProxyMemcExpiry; + global $wgMemc, $wgProxyMemcExpiry, $wgRequest; global $wgProxyKey; if ( !$wgBlockOpenProxies ) { return; } - $ip = wfGetIP(); + $ip = $wgRequest->getIP(); # Get MemCached key $mcKey = wfMemcKey( 'proxy', 'ip', $ip ); Modified: trunk/phase3/includes/RecentChange.php =================================================================== --- trunk/phase3/includes/RecentChange.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/RecentChange.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -361,8 +361,9 @@ */ public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId, $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 ) { + global $wgRequest; if( !$ip ) { - $ip = wfGetIP(); + $ip = $wgRequest->getIP(); if( !$ip ) $ip = ''; } @@ -424,8 +425,9 @@ */ public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot, $ip='', $size=0, $newId=0, $patrol=0 ) { + global $wgRequest; if( !$ip ) { - $ip = wfGetIP(); + $ip = $wgRequest->getIP(); if( !$ip ) $ip = ''; } @@ -484,7 +486,7 @@ $overRedir = false ) { global $wgRequest; if( !$ip ) { - $ip = wfGetIP(); + $ip = $wgRequest->getIP(); if( !$ip ) $ip = ''; } @@ -565,7 +567,7 @@ $type, $action, $target, $logComment, $params, $newId=0 ) { global $wgRequest; if( !$ip ) { - $ip = wfGetIP(); + $ip = $wgRequest->getIP(); if( !$ip ) { $ip = ''; } Modified: trunk/phase3/includes/SkinLegacy.php =================================================================== --- trunk/phase3/includes/SkinLegacy.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/SkinLegacy.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -889,7 +889,7 @@ } function nameAndLogin() { - global $wgUser, $wgLang, $wgContLang; + global $wgUser, $wgLang, $wgRequest, $wgContLang; $logoutPage = $wgContLang->specialPage( 'Userlogout' ); @@ -897,7 +897,7 @@ if ( $wgUser->isAnon() ) { if ( $this->getSkin()->showIPinHeader() ) { - $name = wfGetIP(); + $name = $wgRequest->getIP(); $talkLink = Linker::link( $wgUser->getTalkPage(), $wgLang->getNsText( NS_TALK ) ); Modified: trunk/phase3/includes/Title.php =================================================================== --- trunk/phase3/includes/Title.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/Title.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -1562,7 +1562,7 @@ if ( $reason == '' ) { $reason = wfMsg( 'blockednoreason' ); } - $ip = wfGetIP(); + $ip = $user->getRequest()->getIP(); if ( is_numeric( $id ) ) { $name = User::whoIs( $id ); Modified: trunk/phase3/includes/User.php =================================================================== --- trunk/phase3/includes/User.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/User.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -1259,7 +1259,7 @@ # user is not immune to autoblocks/hardblocks, and they are the current user so we # know which IP address they're actually coming from if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->getID() == $wgUser->getID() ) { - $ip = wfGetIP(); + $ip = $this->getRequest()->getIP(); } else { $ip = null; } @@ -1409,7 +1409,7 @@ */ public function isPingLimitable() { global $wgRateLimitsExcludedIPs; - if( in_array( wfGetIP(), $wgRateLimitsExcludedIPs ) ) { + if( in_array( $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. @@ -1450,7 +1450,7 @@ $limits = $wgRateLimits[$action]; $keys = array(); $id = $this->getId(); - $ip = wfGetIP(); + $ip = $this->getRequet()->getIP(); $userLimit = false; if( isset( $limits['anon'] ) && $id == 0 ) { @@ -1607,7 +1607,7 @@ if( IP::isIPAddress( $this->getName() ) ) { $ip = $this->getName(); } elseif( !$ip ) { - $ip = wfGetIP(); + $ip = $this->getRequest()->getIP(); } $blocked = false; wfRunHooks( 'UserIsBlockedGlobally', array( &$this, $ip, &$blocked ) ); @@ -1685,7 +1685,7 @@ $this->load(); if ( $this->mName === false ) { # Clean up IPs - $this->mName = IP::sanitizeIP( wfGetIP() ); + $this->mName = IP::sanitizeIP( $this->getRequest()->getIP() ); } return $this->mName; } @@ -2943,7 +2943,7 @@ return; } - $userblock->doAutoblock( wfGetIP() ); + $userblock->doAutoblock( $this->getRequest()->getIP() ); } /** @@ -3012,7 +3012,7 @@ # blocked with createaccount disabled, prevent new account creation there even # when the user is logged in if( $this->mBlockedFromCreateAccount === false ){ - $this->mBlockedFromCreateAccount = Block::newFromTarget( null, wfGetIP() ); + $this->mBlockedFromCreateAccount = Block::newFromTarget( null, $this->getRequest()->getIP() ); } return $this->mBlockedFromCreateAccount instanceof Block && $this->mBlockedFromCreateAccount->prevents( 'createaccount' ) ? $this->mBlockedFromCreateAccount @@ -3228,7 +3228,7 @@ return $this->sendMail( wfMsg( 'confirmemail_subject' ), wfMsg( $message, - wfGetIP(), + $this->getRequest()->getIP(), $this->getName(), $url, $wgLang->timeanddate( $expiration, false ), Modified: trunk/phase3/includes/WebRequest.php =================================================================== --- trunk/phase3/includes/WebRequest.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/WebRequest.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -44,6 +44,12 @@ */ private $response; + /** + * Cached client IP address + * @var String + */ + private $ip; + public function __construct() { /// @todo FIXME: This preemptive de-quoting can interfere with other web libraries /// and increases our memory footprint. It would be cleaner to do on @@ -962,6 +968,72 @@ arsort( $langs, SORT_NUMERIC ); return $langs; } + + /** + * Fetch the raw IP from the request + * + * @return String + */ + protected function getRawIP() { + if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { + return IP::canonicalize( $_SERVER['REMOTE_ADDR'] ); + } else { + return null; + } + } + + /** + * Work out the IP address based on various globals + * For trusted proxies, use the XFF client IP (first of the chain) + * @return string + */ + public function getIP() { + global $wgUsePrivateIPs; + + # Return cached result + if ( $this->ip !== null ) { + return $this->ip; + } + + # collect the originating ips + $ip = $this->getRawIP(); + + # Append XFF + $forwardedFor = $this->getHeader( 'X-Forwarded-For' ); + if ( $forwardedFor !== false ) { + $ipchain = array_map( 'trim', explode( ',', $forwardedFor ) ); + $ipchain = array_reverse( $ipchain ); + if ( $ip ) { + array_unshift( $ipchain, $ip ); + } + + # Step through XFF list and find the last address in the list which is a trusted server + # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private) + foreach ( $ipchain as $i => $curIP ) { + $curIP = IP::canonicalize( $curIP ); + if ( wfIsTrustedProxy( $curIP ) ) { + if ( isset( $ipchain[$i + 1] ) ) { + if ( $wgUsePrivateIPs || IP::isPublic( $ipchain[$i + 1 ] ) ) { + $ip = $ipchain[$i + 1]; + } + } + } else { + break; + } + } + } + + # Allow extensions to improve our guess + wfRunHooks( 'GetIP', array( &$ip ) ); + + if ( !$ip ) { + throw new MWException( "Unable to determine IP" ); + } + + wfDebug( "IP: $ip\n" ); + $this->ip = $ip; + return $ip; + } } /** @@ -1165,4 +1237,8 @@ public function checkUrlExtension( $extWhitelist = array() ) { return true; } + + protected function getRawIP() { + return '127.0.0.1'; + } } Modified: trunk/phase3/includes/specials/SpecialBlockme.php =================================================================== --- trunk/phase3/includes/specials/SpecialBlockme.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/specials/SpecialBlockme.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -38,7 +38,7 @@ $this->setHeaders(); $this->outputHeader(); - $ip = wfGetIP(); + $ip = $wgRequest->getIP(); if( !$wgBlockOpenProxies || $wgRequest->getText( 'ip' ) != md5( $ip . $wgProxyKey ) ) { $wgOut->addWikiMsg( 'proxyblocker-disabled' ); return; Modified: trunk/phase3/includes/specials/SpecialPasswordReset.php =================================================================== --- trunk/phase3/includes/specials/SpecialPasswordReset.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/specials/SpecialPasswordReset.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -162,7 +162,7 @@ // We need to have a valid IP address for the hook, but per bug 18347, we should // send the user's name if they're logged in. - $ip = wfGetIP(); + $ip = $this->getRequest()->getIP(); if ( !$ip ) { return array( 'badipaddress' ); } Modified: trunk/phase3/includes/specials/SpecialUserlogin.php =================================================================== --- trunk/phase3/includes/specials/SpecialUserlogin.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/specials/SpecialUserlogin.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -251,7 +251,7 @@ * @private */ function addNewAccountInternal() { - global $wgUser, $wgOut; + global $wgUser, $wgOut, $wgRequest; global $wgMemc, $wgAccountCreationThrottle; global $wgAuth, $wgMinimalPasswordLength; global $wgEmailConfirmToEdit; @@ -308,7 +308,7 @@ return false; } - $ip = wfGetIP(); + $ip = $wgRequest->getIP(); if ( $wgUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) { $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' ); return false; @@ -588,12 +588,12 @@ * @return Bool|Integer The integer hit count or True if it is already at the limit */ public static function incLoginThrottle( $username ) { - global $wgPasswordAttemptThrottle, $wgMemc; + global $wgPasswordAttemptThrottle, $wgMemc, $wgRequest; $username = trim( $username ); // sanity $throttleCount = 0; if ( is_array( $wgPasswordAttemptThrottle ) ) { - $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $username ) ); + $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) ); $count = $wgPasswordAttemptThrottle['count']; $period = $wgPasswordAttemptThrottle['seconds']; @@ -616,10 +616,10 @@ * @return void */ public static function clearLoginThrottle( $username ) { - global $wgMemc; + global $wgMemc, $wgRequest; $username = trim( $username ); // sanity - $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $username ) ); + $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) ); $wgMemc->delete( $throttleKey ); } @@ -682,7 +682,7 @@ } function processLogin() { - global $wgUser; + global $wgUser, $wgRequest, $wgLang; switch ( $this->authenticateUserData() ) { case self::SUCCESS: @@ -697,7 +697,7 @@ self::clearLoginToken(); // Reset the throttle - $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mUsername ) ); + $key = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $this->mUsername ) ); global $wgMemc; $wgMemc->delete( $key ); @@ -705,7 +705,6 @@ /* Replace the language object to provide user interface in * correct language immediately on this first page load. */ - global $wgLang, $wgRequest; $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) ); $wgLang = Language::factory( $code ); return $this->successfulLogin(); @@ -779,12 +778,12 @@ * @private */ function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) { - global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry; + global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry, $wgRequest; if ( $u->getEmail() == '' ) { return Status::newFatal( 'noemail', $u->getName() ); } - $ip = wfGetIP(); + $ip = $wgRequest->getIP(); if( !$ip ) { return Status::newFatal( 'badipaddress' ); } Modified: trunk/phase3/includes/specials/SpecialVersion.php =================================================================== --- trunk/phase3/includes/specials/SpecialVersion.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/includes/specials/SpecialVersion.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -502,7 +502,7 @@ * @return String: HTML fragment */ private function IPInfo() { - $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) ); + $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) ); return "<!-- visited from $ip -->\n" . "<span style='display:none'>visited from $ip</span>"; } Modified: trunk/phase3/tests/phpunit/includes/WebRequestTest.php =================================================================== --- trunk/phase3/tests/phpunit/includes/WebRequestTest.php 2011-08-18 19:55:55 UTC (rev 94931) +++ trunk/phase3/tests/phpunit/includes/WebRequestTest.php 2011-08-18 20:03:30 UTC (rev 94932) @@ -85,4 +85,102 @@ ), ); } + + /** + * @dataProvider provideGetIP + */ + function testGetIP( $expected, $input, $squid, $private, $description ) { + global $wgSquidServersNoPurge, $wgUsePrivateIPs; + $oldServer = $_SERVER; + $_SERVER = $input; + $wgSquidServersNoPurge = $squid; + $wgUsePrivateIPs = $private; + $request = new WebRequest(); + $result = $request->getIP(); + $_SERVER = $oldServer; + $this->assertEquals( $expected, $result, $description ); + } + + function provideGetIP() { + return array( + array( + '127.0.0.1', + array( + 'REMOTE_ADDR' => '127.0.0.1' + ), + array(), + false, + 'Simple IPv4' + ), + array( + '::1', + array( + 'REMOTE_ADDR' => '::1' + ), + array(), + false, + 'Simple IPv6' + ), + array( + '12.0.0.3', + array( + 'REMOTE_ADDR' => '12.0.0.1', + 'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2' + ), + array( '12.0.0.1', '12.0.0.2' ), + false, + 'With X-Forwaded-For' + ), + array( + '12.0.0.1', + array( + 'REMOTE_ADDR' => '12.0.0.1', + 'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2' + ), + array(), + false, + 'With X-Forwaded-For and disallowed server' + ), + array( + '12.0.0.2', + array( + 'REMOTE_ADDR' => '12.0.0.1', + 'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2' + ), + array( '12.0.0.1' ), + false, + 'With multiple X-Forwaded-For and only one allowed server' + ), + array( + '12.0.0.2', + array( + 'REMOTE_ADDR' => '12.0.0.2', + 'HTTP_X_FORWARDED_FOR' => '10.0.0.3, 12.0.0.2' + ), + array( '12.0.0.1', '12.0.0.2' ), + false, + 'With X-Forwaded-For and private IP' + ), + array( + '10.0.0.3', + array( + 'REMOTE_ADDR' => '12.0.0.2', + 'HTTP_X_FORWARDED_FOR' => '10.0.0.3, 12.0.0.2' + ), + array( '12.0.0.1', '12.0.0.2' ), + true, + 'With X-Forwaded-For and private IP (allowed)' + ), + ); + } + + /** + * @expectedException MWException + */ + function testGetIpLackOfRemoteAddrThrowAnException() { + var_dump( $_SERVER ); + $request = new WebRequest(); + # Next call throw an exception about lacking an IP + $request->getIP(); + } } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs