Index: trunk/phase3/tests/phpunit/includes/ProxyTools/wfGetIPTest.php |
— | — | @@ -9,14 +9,12 @@ |
10 | 10 | * TODO: need to cover the part dealing with XFF headers. |
11 | 11 | */ |
12 | 12 | class wfGetIPTest extends MediaWikiTestCase { |
13 | | - // constant used to reset wfGetIP() internal static variable |
14 | | - const doReset = true; |
15 | 13 | |
16 | 14 | /** helper */ |
17 | 15 | public function assertIP( $expected, $msg = '' ) { |
18 | 16 | $this->assertEquals( |
19 | 17 | $expected, |
20 | | - wfGetIP( wfGetIPTest::doReset ), |
| 18 | + wfGetIP( 'reset' ), |
21 | 19 | $msg ); |
22 | 20 | } |
23 | 21 | |
— | — | @@ -24,13 +22,10 @@ |
25 | 23 | public function assertIPNot( $expected, $msg = '' ) { |
26 | 24 | $this->assertNotEquals( |
27 | 25 | $expected, |
28 | | - wfGetIP( wfGetIPTest::doReset ), |
| 26 | + wfGetIP( 'reset' ), |
29 | 27 | $msg ); |
30 | 28 | } |
31 | 29 | |
32 | | - /** |
33 | | - * @group Broken |
34 | | - */ |
35 | 30 | function testGetLoopbackAddressWhenInCommandLine() { |
36 | 31 | global $wgCommandLineMode; |
37 | 32 | $save = $wgCommandLineMode; |
— | — | @@ -42,9 +37,6 @@ |
43 | 38 | $wgCommandLineMode = $save; |
44 | 39 | } |
45 | 40 | |
46 | | - /** |
47 | | - * @group Broken |
48 | | - */ |
49 | 41 | function testGetFromServerRemoteAddr() { |
50 | 42 | global $_SERVER; |
51 | 43 | $save = null; |
— | — | @@ -70,11 +62,17 @@ |
71 | 63 | } else { |
72 | 64 | $_SERVER['REMOTE_ADDR'] = $save; |
73 | 65 | } |
| 66 | + # Restore internal static altered above |
| 67 | + wfGetIP( 'reset' ); |
74 | 68 | } |
75 | 69 | |
76 | 70 | /** |
77 | 71 | * @expectedException MWException |
78 | 72 | * @group Broken |
| 73 | + * This is broken since it alter $wgCommandLineMode which is needed |
| 74 | + * by our exception handler. Until someone find a correct way to handle |
| 75 | + * this case, the test should stay in the Broken group. |
| 76 | + * |
79 | 77 | */ |
80 | 78 | function testLackOfRemoteAddrThrowAnException() { |
81 | 79 | global $wgCommandLineMode; |
— | — | @@ -83,7 +81,7 @@ |
84 | 82 | # PHPUnit runs from the command line |
85 | 83 | $wgCommandLineMode = false; |
86 | 84 | # Next call throw an exception about lacking an IP |
87 | | - wfGetIP( wfGetIPTest::doReset ); |
| 85 | + wfGetIP( 'reset' ); |
88 | 86 | |
89 | 87 | $wgCommandLineMode = $save; |
90 | 88 | } |
Index: trunk/phase3/includes/ProxyTools.php |
— | — | @@ -64,12 +64,19 @@ |
65 | 65 | /** |
66 | 66 | * Work out the IP address based on various globals |
67 | 67 | * For trusted proxies, use the XFF client IP (first of the chain) |
| 68 | + * @param $reset boolean Used to reset the internal static variable |
| 69 | + * tracking the IP address. Set to anything non empty to reset it, for |
| 70 | + * example: wfGetIP( 'reset' ); (default: false). |
68 | 71 | * @return string |
69 | 72 | */ |
70 | | -function wfGetIP() { |
| 73 | +function wfGetIP( $reset = false ) { |
71 | 74 | global $wgUsePrivateIPs, $wgCommandLineMode; |
72 | 75 | static $ip = false; |
73 | 76 | |
| 77 | + if( $reset ) { |
| 78 | + $ip = false; |
| 79 | + } |
| 80 | + |
74 | 81 | # Return cached result |
75 | 82 | if ( !empty( $ip ) ) { |
76 | 83 | return $ip; |