mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 16:04:25 +02:00
MDL-67861 core: Fix getremoteaddr unit test to match new proxy setup
This commit is contained in:
parent
ff1a10333d
commit
c02a85c786
@ -3643,6 +3643,10 @@ class core_moodlelib_testcase extends advanced_testcase {
|
||||
* Tests the getremoteaddr() function.
|
||||
*/
|
||||
public function test_getremoteaddr() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$CFG->getremoteaddrconf = GETREMOTEADDR_SKIP_HTTP_CLIENT_IP;
|
||||
$xforwardedfor = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : null;
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '';
|
||||
@ -3659,27 +3663,27 @@ class core_moodlelib_testcase extends advanced_testcase {
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,127.0.0.2';
|
||||
$twoip = getremoteaddr();
|
||||
$this->assertEquals('127.0.0.1', $twoip);
|
||||
$this->assertEquals('127.0.0.2', $twoip);
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,127.0.0.2, 127.0.0.3';
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,127.0.0.2,127.0.0.3';
|
||||
$threeip = getremoteaddr();
|
||||
$this->assertEquals('127.0.0.1', $threeip);
|
||||
$this->assertEquals('127.0.0.3', $threeip);
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1:65535,127.0.0.2';
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,127.0.0.2:65535';
|
||||
$portip = getremoteaddr();
|
||||
$this->assertEquals('127.0.0.1', $portip);
|
||||
$this->assertEquals('127.0.0.2', $portip);
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '0:0:0:0:0:0:0:1,127.0.0.2';
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,0:0:0:0:0:0:0:2';
|
||||
$portip = getremoteaddr();
|
||||
$this->assertEquals('0:0:0:0:0:0:0:1', $portip);
|
||||
$this->assertEquals('0:0:0:0:0:0:0:2', $portip);
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '0::1,127.0.0.2';
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,0::2';
|
||||
$portip = getremoteaddr();
|
||||
$this->assertEquals('0:0:0:0:0:0:0:1', $portip);
|
||||
$this->assertEquals('0:0:0:0:0:0:0:2', $portip);
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '[0:0:0:0:0:0:0:1]:65535,127.0.0.2';
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,[0:0:0:0:0:0:0:2]:65535';
|
||||
$portip = getremoteaddr();
|
||||
$this->assertEquals('0:0:0:0:0:0:0:1', $portip);
|
||||
$this->assertEquals('0:0:0:0:0:0:0:2', $portip);
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = $xforwardedfor;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user