aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/request.php
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-09-03 11:04:49 +0200
committerLukas Reschke <lukas@owncloud.com>2014-09-03 11:04:49 +0200
commit77c0adb520adcb100d2ef4fd0562330b209ee9ea (patch)
tree9bae923fa05f312c033722ad2c711cec01758ab0 /tests/lib/request.php
parent50b430ee7cadd6be1520d63acdac27bc06581e09 (diff)
parentfe74b397a53b8a568c15d1ccf779bc8b0425b3c5 (diff)
downloadnextcloud-server-77c0adb520adcb100d2ef4fd0562330b209ee9ea.tar.gz
nextcloud-server-77c0adb520adcb100d2ef4fd0562330b209ee9ea.zip
Merge branch 'securityutils' of https://github.com/owncloud/core into securityutils
Diffstat (limited to 'tests/lib/request.php')
-rw-r--r--tests/lib/request.php38
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