Merge pull request #17078 from owncloud/fix-initial-server-host
Fix undefined offset
This commit is contained in:
commit
da45fad3eb
|
@ -659,11 +659,6 @@ class Request implements \ArrayAccess, \Countable, IRequest {
|
||||||
* @return string Server host
|
* @return string Server host
|
||||||
*/
|
*/
|
||||||
public function getServerHost() {
|
public function getServerHost() {
|
||||||
// FIXME: Ugly workaround that we need to get rid of
|
|
||||||
if (\OC::$CLI && defined('PHPUNIT_RUN')) {
|
|
||||||
return 'localhost';
|
|
||||||
}
|
|
||||||
|
|
||||||
// overwritehost is always trusted
|
// overwritehost is always trusted
|
||||||
$host = $this->getOverwriteHost();
|
$host = $this->getOverwriteHost();
|
||||||
if ($host !== null) {
|
if ($host !== null) {
|
||||||
|
@ -681,7 +676,11 @@ class Request implements \ArrayAccess, \Countable, IRequest {
|
||||||
return $host;
|
return $host;
|
||||||
} else {
|
} else {
|
||||||
$trustedList = $this->config->getSystemValue('trusted_domains', []);
|
$trustedList = $this->config->getSystemValue('trusted_domains', []);
|
||||||
|
if(!empty($trustedList)) {
|
||||||
return $trustedList[0];
|
return $trustedList[0];
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -773,7 +773,23 @@ class RequestTest extends \Test\TestCase {
|
||||||
$this->assertEquals('from.forwarded.host2:8080', $request->getInsecureServerHost());
|
$this->assertEquals('from.forwarded.host2:8080', $request->getInsecureServerHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetServerHost() {
|
public function testGetServerHostWithOverwriteHost() {
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(0))
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('overwritehost')
|
||||||
|
->will($this->returnValue('my.overwritten.host'));
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(1))
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('overwritecondaddr')
|
||||||
|
->will($this->returnValue(''));
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(2))
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('overwritehost')
|
||||||
|
->will($this->returnValue('my.overwritten.host'));
|
||||||
|
|
||||||
$request = new Request(
|
$request = new Request(
|
||||||
[],
|
[],
|
||||||
$this->secureRandom,
|
$this->secureRandom,
|
||||||
|
@ -781,7 +797,80 @@ class RequestTest extends \Test\TestCase {
|
||||||
$this->stream
|
$this->stream
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals('localhost', $request->getServerHost());
|
$this->assertEquals('my.overwritten.host', $request->getServerHost());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetServerHostWithTrustedDomain() {
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(3))
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('trusted_domains')
|
||||||
|
->will($this->returnValue(['my.trusted.host']));
|
||||||
|
|
||||||
|
$request = new Request(
|
||||||
|
[
|
||||||
|
'server' => [
|
||||||
|
'HTTP_X_FORWARDED_HOST' => 'my.trusted.host',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
$this->secureRandom,
|
||||||
|
$this->config,
|
||||||
|
$this->stream
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals('my.trusted.host', $request->getServerHost());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetServerHostWithUntrustedDomain() {
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(3))
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('trusted_domains')
|
||||||
|
->will($this->returnValue(['my.trusted.host']));
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(4))
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('trusted_domains')
|
||||||
|
->will($this->returnValue(['my.trusted.host']));
|
||||||
|
|
||||||
|
$request = new Request(
|
||||||
|
[
|
||||||
|
'server' => [
|
||||||
|
'HTTP_X_FORWARDED_HOST' => 'my.untrusted.host',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
$this->secureRandom,
|
||||||
|
$this->config,
|
||||||
|
$this->stream
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals('my.trusted.host', $request->getServerHost());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetServerHostWithNoTrustedDomain() {
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(3))
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('trusted_domains')
|
||||||
|
->will($this->returnValue([]));
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(4))
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('trusted_domains')
|
||||||
|
->will($this->returnValue([]));
|
||||||
|
|
||||||
|
$request = new Request(
|
||||||
|
[
|
||||||
|
'server' => [
|
||||||
|
'HTTP_X_FORWARDED_HOST' => 'my.untrusted.host',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
$this->secureRandom,
|
||||||
|
$this->config,
|
||||||
|
$this->stream
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals('', $request->getServerHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetOverwriteHostDefaultNull() {
|
public function testGetOverwriteHostDefaultNull() {
|
||||||
|
|
Loading…
Reference in New Issue