diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-07-17 14:20:57 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-07-17 14:20:57 +0200 |
commit | 1b8eb668de489d23912983c7250d4abe44ad7fb5 (patch) | |
tree | a36f0b210667ea722b7df931fca620aef24c4645 | |
parent | 015d4e3ba373ff3bb60abb036ef3e53731f33799 (diff) | |
parent | fc6420c2905b63017d3ea23eee8a542987d5b286 (diff) | |
download | nextcloud-server-1b8eb668de489d23912983c7250d4abe44ad7fb5.tar.gz nextcloud-server-1b8eb668de489d23912983c7250d4abe44ad7fb5.zip |
Merge pull request #17697 from owncloud/fix-undefined-REMOTE_ADDR-stable8.1
Fixing 'Undefined index: REMOTE_ADDR' - fixes #17460
-rw-r--r-- | lib/private/appframework/http/request.php | 3 | ||||
-rw-r--r-- | tests/lib/appframework/http/RequestTest.php | 19 |
2 files changed, 17 insertions, 5 deletions
diff --git a/lib/private/appframework/http/request.php b/lib/private/appframework/http/request.php index 7d6a49202c6..d3ebcfc6925 100644 --- a/lib/private/appframework/http/request.php +++ b/lib/private/appframework/http/request.php @@ -478,7 +478,8 @@ class Request implements \ArrayAccess, \Countable, IRequest { */ private function isOverwriteCondition($type = '') { $regex = '/' . $this->config->getSystemValue('overwritecondaddr', '') . '/'; - return $regex === '//' || preg_match($regex, $this->server['REMOTE_ADDR']) === 1 + $remoteAddr = isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : ''; + return $regex === '//' || preg_match($regex, $remoteAddr) === 1 || $type !== 'protocol'; } diff --git a/tests/lib/appframework/http/RequestTest.php b/tests/lib/appframework/http/RequestTest.php index a4bf3519bfc..f011d7f72bd 100644 --- a/tests/lib/appframework/http/RequestTest.php +++ b/tests/lib/appframework/http/RequestTest.php @@ -1023,17 +1023,27 @@ class RequestTest extends \Test\TestCase { $this->assertSame('/test.php', $request->getRequestUri()); } - public function testGetRequestUriWithOverwrite() { + public function providesGetRequestUriWithOverwriteData() { + return [ + ['/scriptname.php/some/PathInfo', '/owncloud/', ''], + ['/scriptname.php/some/PathInfo', '/owncloud/', '123'], + ]; + } + + /** + * @dataProvider providesGetRequestUriWithOverwriteData + */ + public function testGetRequestUriWithOverwrite($expectedUri, $overwriteWebRoot, $overwriteCondAddr) { $this->config ->expects($this->at(0)) ->method('getSystemValue') ->with('overwritewebroot') - ->will($this->returnValue('/owncloud/')); + ->will($this->returnValue($overwriteWebRoot)); $this->config ->expects($this->at(1)) ->method('getSystemValue') ->with('overwritecondaddr') - ->will($this->returnValue('')); + ->will($this->returnValue($overwriteCondAddr)); $request = $this->getMockBuilder('\OC\AppFramework\Http\Request') ->setMethods(['getScriptName']) @@ -1054,6 +1064,7 @@ class RequestTest extends \Test\TestCase { ->method('getScriptName') ->will($this->returnValue('/scriptname.php')); - $this->assertSame('/scriptname.php/some/PathInfo', $request->getRequestUri()); + $this->assertSame($expectedUri, $request->getRequestUri()); } + } |