e72408f6b0213ec5035d4dee0608a4152ef895bd
3 class WebRequestTest
extends MediaWikiTestCase
{
5 * @dataProvider provideDetectServer
7 function testDetectServer( $expected, $input, $description ) {
10 $result = WebRequest
::detectServer();
11 $_SERVER = $oldServer;
12 $this->assertEquals( $expected, $result, $description );
15 function provideDetectServer() {
30 'Host header with secure'
38 'Default SERVER_PORT',
61 'Host server name precedence'
66 'HTTP_HOST' => '[::1]',
67 'SERVER_NAME' => '::1',
68 'SERVER_PORT' => '81',
75 'SERVER_NAME' => '[2001'
77 'Kind of like lighttpd per commit message in MW r83847',
80 'http://[2a01:e35:2eb4:1::2]:777',
82 'SERVER_NAME' => '[2a01:e35:2eb4:1::2]:777'
84 'Possible lighttpd environment per bug 14977 comment 13',
90 * @dataProvider provideGetIP
92 function testGetIP( $expected, $input, $squid, $private, $description ) {
93 global $wgSquidServersNoPurge, $wgUsePrivateIPs;
94 $oldServer = $_SERVER;
96 $wgSquidServersNoPurge = $squid;
97 $wgUsePrivateIPs = $private;
98 $request = new WebRequest();
99 $result = $request->getIP();
100 $_SERVER = $oldServer;
101 $this->assertEquals( $expected, $result, $description );
104 function provideGetIP() {
109 'REMOTE_ADDR' => '127.0.0.1'
118 'REMOTE_ADDR' => '::1'
127 'REMOTE_ADDR' => '12.0.0.1',
128 'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
130 array( '12.0.0.1', '12.0.0.2' ),
132 'With X-Forwaded-For'
137 'REMOTE_ADDR' => '12.0.0.1',
138 'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
142 'With X-Forwaded-For and disallowed server'
147 'REMOTE_ADDR' => '12.0.0.1',
148 'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
152 'With multiple X-Forwaded-For and only one allowed server'
157 'REMOTE_ADDR' => '12.0.0.2',
158 'HTTP_X_FORWARDED_FOR' => '10.0.0.3, 12.0.0.2'
160 array( '12.0.0.1', '12.0.0.2' ),
162 'With X-Forwaded-For and private IP'
167 'REMOTE_ADDR' => '12.0.0.2',
168 'HTTP_X_FORWARDED_FOR' => '10.0.0.3, 12.0.0.2'
170 array( '12.0.0.1', '12.0.0.2' ),
172 'With X-Forwaded-For and private IP (allowed)'
178 * @expectedException MWException
180 function testGetIpLackOfRemoteAddrThrowAnException() {
181 $request = new WebRequest();
182 # Next call throw an exception about lacking an IP