Fixing 'Undefined index: REMOTE_ADDR' - fixes #17460

This commit is contained in:
Thomas Müller 2015-07-16 16:40:57 +02:00
parent 15877ac7eb
commit bd71540c8a
2 changed files with 17 additions and 5 deletions

View File

@ -478,7 +478,8 @@ class Request implements \ArrayAccess, \Countable, IRequest {
*/ */
private function isOverwriteCondition($type = '') { private function isOverwriteCondition($type = '') {
$regex = '/' . $this->config->getSystemValue('overwritecondaddr', '') . '/'; $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'; || $type !== 'protocol';
} }

View File

@ -1112,17 +1112,27 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('/test.php', $request->getRequestUri()); $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 $this->config
->expects($this->at(0)) ->expects($this->at(0))
->method('getSystemValue') ->method('getSystemValue')
->with('overwritewebroot') ->with('overwritewebroot')
->will($this->returnValue('/owncloud/')); ->will($this->returnValue($overwriteWebRoot));
$this->config $this->config
->expects($this->at(1)) ->expects($this->at(1))
->method('getSystemValue') ->method('getSystemValue')
->with('overwritecondaddr') ->with('overwritecondaddr')
->will($this->returnValue('')); ->will($this->returnValue($overwriteCondAddr));
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request') $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
->setMethods(['getScriptName']) ->setMethods(['getScriptName'])
@ -1143,6 +1153,7 @@ class RequestTest extends \Test\TestCase {
->method('getScriptName') ->method('getScriptName')
->will($this->returnValue('/scriptname.php')); ->will($this->returnValue('/scriptname.php'));
$this->assertSame('/scriptname.php/some/PathInfo', $request->getRequestUri()); $this->assertSame($expectedUri, $request->getRequestUri());
} }
} }