Move overwritehost check to isTrustedDomain

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-12-02 10:48:41 +01:00 committed by John Molakvoæ (skjnldsv)
parent 2959487f71
commit d05f131929
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
3 changed files with 21 additions and 4 deletions

View File

@ -760,9 +760,6 @@ class OC {
* FIXME: Should not be in here at all :see_no_evil:
*/
if (!OC::$CLI
// overwritehost is always trusted, workaround to not have to make
// \OC\AppFramework\Http\Request::getOverwriteHost public
&& self::$server->getConfig()->getSystemValue('overwritehost') === ''
&& !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host)
&& self::$server->getConfig()->getSystemValue('installed', false)
) {

View File

@ -70,6 +70,11 @@ class TrustedDomainHelper {
* have been configured
*/
public function isTrustedDomain($domainWithPort) {
// overwritehost is always trusted
if ($this->config->getSystemValue('overwritehost') !== '') {
return true;
}
$domain = $this->getDomainWithoutPort($domainWithPort);
// Read trusted domains from config

View File

@ -31,7 +31,11 @@ class TrustedDomainHelperTest extends \Test\TestCase {
* @param bool $result
*/
public function testIsTrustedDomain($trustedDomains, $testDomain, $result) {
$this->config->expects($this->once())
$this->config->expects($this->at(0))
->method('getSystemValue')
->with('overwritehost')
->will($this->returnValue(''));
$this->config->expects($this->at(1))
->method('getSystemValue')
->with('trusted_domains')
->will($this->returnValue($trustedDomains));
@ -113,4 +117,15 @@ class TrustedDomainHelperTest extends \Test\TestCase {
[$trustedHostTestList, 'LOWERCASE.DOMAIN', true],
];
}
public function testIsTrustedDomainOverwriteHost() {
$this->config->expects($this->at(0))
->method('getSystemValue')
->with('overwritehost')
->will($this->returnValue('myproxyhost'));
$trustedDomainHelper = new TrustedDomainHelper($this->config);
$this->assertTrue($trustedDomainHelper->isTrustedDomain('myproxyhost'));
$this->assertTrue($trustedDomainHelper->isTrustedDomain('myotherhost'));
}
}