diff options
author | Lukas Reschke <lukas@owncloud.com> | 2014-08-26 23:58:13 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2014-08-27 00:05:04 +0200 |
commit | 7acdd018a1555c9bc5dcc1702074a10f862bb170 (patch) | |
tree | adbbeff4dfb9f0dca4ae27902448cde6c141c771 /tests | |
parent | 3115053bbb3a1ba5d0bb3562bea6b7ef94a09cd0 (diff) | |
download | nextcloud-server-7acdd018a1555c9bc5dcc1702074a10f862bb170.tar.gz nextcloud-server-7acdd018a1555c9bc5dcc1702074a10f862bb170.zip |
Add support for getting the real client IP behind proxies
Fixes https://github.com/owncloud/core/issues/10624
Fix copy paste fail
Add unittest for comma separated headers
Revert 3rdparty
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/request.php | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/tests/lib/request.php b/tests/lib/request.php index bff84e1b03f..b89bf92ece7 100644 --- a/tests/lib/request.php +++ b/tests/lib/request.php @@ -9,21 +9,53 @@ class Test_Request extends PHPUnit_Framework_TestCase { public function setUp() { - OC_Config::setValue('overwritewebroot', '/domain.tld/ownCloud'); + OC::$server->getConfig()->setSystemValue('overwritewebroot', '/domain.tld/ownCloud'); + + OC::$server->getConfig()->setSystemValue('trusted_proxies', array()); + OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array()); } public function tearDown() { - OC_Config::setValue('overwritewebroot', ''); + OC::$server->getConfig()->setSystemValue('overwritewebroot', ''); + OC::$server->getConfig()->setSystemValue('trusted_proxies', array()); + OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array()); } public function testScriptNameOverWrite() { $_SERVER['REMOTE_ADDR'] = '10.0.0.1'; - $_SERVER["SCRIPT_FILENAME"] = __FILE__; + $_SERVER['SCRIPT_FILENAME'] = __FILE__; $scriptName = OC_Request::scriptName(); $this->assertEquals('/domain.tld/ownCloud/tests/lib/request.php', $scriptName); } + public function testGetRemoteAddress() { + $_SERVER['REMOTE_ADDR'] = '10.0.0.2'; + $_SERVER['HTTP_X_FORWARDED'] = '10.4.0.5, 10.4.0.4'; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.0.233'; + + // Without having specified a trusted remote address + $this->assertEquals('10.0.0.2', OC_Request::getRemoteAddress()); + + // With specifying a trusted remote address but no trusted header + OC::$server->getConfig()->setSystemValue('trusted_proxies', array('10.0.0.2')); + $this->assertEquals('10.0.0.2', OC_Request::getRemoteAddress()); + + // With specifying a trusted remote address and trusted headers + OC::$server->getConfig()->setSystemValue('trusted_proxies', array('10.0.0.2')); + OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_X_FORWARDED')); + $this->assertEquals('10.4.0.5', OC_Request::getRemoteAddress()); + OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED')); + $this->assertEquals('192.168.0.233', OC_Request::getRemoteAddress()); + + // With specifying multiple trusted remote addresses and trusted headers + OC::$server->getConfig()->setSystemValue('trusted_proxies', array('10.3.4.2', '10.0.0.2', '127.0.3.3')); + OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_X_FORWARDED')); + $this->assertEquals('10.4.0.5', OC_Request::getRemoteAddress()); + OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED')); + $this->assertEquals('192.168.0.233', OC_Request::getRemoteAddress()); + } + /** * @dataProvider rawPathInfoProvider * @param $expected |